x-requested-with: XMLHttpRequest是什么?

zlcp520 2011-09-02 09:09:52
POST /comments/itemcomment.srv?method=add HTTP/1.1
x-requested-with: XMLHttpRequest
Accept-Language: zh-cn
Referer: http://www.tudou.com/programs/view/5yKUbsjqpx4/
Accept: application/json, text/javascript, */*
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 691; TencentTraveler 4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)
Host: www.tudou.com
Content-Length: 75
Connection: Keep-Alive

x-requested-with: XMLHttpRequest
抓包信息中的这是什么意思?应该怎么模拟?

我直接

Headers.Set("x-requested-with", "XMLHttpRequest");

返回服务器错误啊

...全文
36647 23 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
nazicp 2014-02-12
  • 打赏
  • 举报
回复
发送的话使用RestSharp直接Add一个Parameter并设置好ParameterType即可
nazicp 2014-02-12
  • 打赏
  • 举报
回复
System.Web.WebPages namespace里的WebPageRenderingBase类有个属性,叫做IsAjax.就是用来判断是否存在这个头的,和IsPost用法类似
单纯的夙愿 2013-11-11
  • 打赏
  • 举报
回复 1
如果发送的是ajax同步请求呢(即async:false,)那么,X-Requested-With有值吗
qiouqfz 2013-07-19
  • 打赏
  • 举报
回复
正需要这个功能
jayrao5566 2011-09-03
  • 打赏
  • 举报
回复
什么是 XMLHttpRequest 对象?

XMLHttpRequest 对象用于在后台与服务器交换数据。

XMLHttpRequest 对象是开发者的梦想,因为您能够:

在不重新加载页面的情况下更新网页
在页面已加载后从服务器请求数据
在页面已加载后从服务器接收数据
在后台向服务器发送数据

所有现代的浏览器都支持 XMLHttpRequest 对象。

http://www.w3school.com.cn/xml/xml_http.asp
zlcp520 2011-09-03
  • 打赏
  • 举报
回复
搞定了,加个这样的设置就可以了
ProtocolVersion = new Version("1.0");
快溜 2011-09-03
  • 打赏
  • 举报
回复
实现ajax技术的一个对象
zlcp520 2011-09-03
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 jayrao5566 的回复:]
JScript code
什么是 XMLHttpRequest 对象?

XMLHttpRequest 对象用于在后台与服务器交换数据。

XMLHttpRequest 对象是开发者的梦想,因为您能够:

在不重新加载页面的情况下更新网页
在页面已加载后从服务器请求数据
在页面已加载后从服务器接收数据
在后台向服务器发送数据

所有现代的浏览……
[/Quote]

我是要C#模拟XMLHttpRequest
zlcp520 2011-09-02
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 taomanman 的回复:]
引用 12 楼 zlcp520 的回复:

引用 11 楼 taomanman 的回复:
判断是否为ajaxRequest 在http请求头中查找是否包含X-Requested-With,并且值为XMLHttpRequest

C# code

string sheader = Request.header["X-Requested-With"];
bool isAjaxReque……
[/Quote]

网站留言,是直接这样加吗Headers.Add("X-Requested-With", "XMLHttpRequest");
还是返回错误啊,可能cookie有判断吧.
LMAOhuaNL 2011-09-02
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 hexytxl 的回复:]
在服务器端判断request来自Ajax请求(异步)还是传统请求(同步)


在服务器端判断request来自Ajax请求(异步)还是传统请求(同步):

两种请求在请求的Header不同,Ajax 异步请求比传统的同步请求多了一个头参数

1、传统同步请求参数

accept text/html,application/xhtml+xml,application/xml……
[/Quote]
够详细
暖枫无敌 2011-09-02
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 zlcp520 的回复:]

引用 11 楼 taomanman 的回复:
判断是否为ajaxRequest 在http请求头中查找是否包含X-Requested-With,并且值为XMLHttpRequest

C# code

string sheader = Request.header["X-Requested-With"];
bool isAjaxRequest = (sheade != null &a……
[/Quote]
你想干嘛?实现模拟POST发送请求登录网站 ???
zlcp520 2011-09-02
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 taomanman 的回复:]
判断是否为ajaxRequest 在http请求头中查找是否包含X-Requested-With,并且值为XMLHttpRequest

C# code

string sheader = Request.header["X-Requested-With"];
bool isAjaxRequest = (sheade != null && sheader == "XMLH……
[/Quote]

哥哥,我是winform模拟Http协议发送啊,是要添加头不是获取头啊,是不是异步无法模拟发送啊?
暖枫无敌 2011-09-02
  • 打赏
  • 举报
回复
判断是否为ajaxRequest 在http请求头中查找是否包含X-Requested-With,并且值为XMLHttpRequest

string sheader = Request.header["X-Requested-With"];
bool isAjaxRequest = (sheade != null && sheader == "XMLHttpRequest") ? true : false;
zlcp520 2011-09-02
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 taomanman 的回复:]
C# code

private string HttpPost(string URI, string Parameters)
{
System.Net.WebRequest req = System.Net.WebRequest.Create(URI);
req.Proxy = new System.Net.WebProxy(ProxyString, true);

……
[/Quote]


这个知道 啊,就是不知道x-requested-with: XMLHttpRequest
这个类型的,也就是异步发送的怎么模拟啊.这个页头怎么添加啊,不添加返回服务器错误.
暖枫无敌 2011-09-02
  • 打赏
  • 举报
回复

private string HttpPost(string URI, string Parameters)
{
System.Net.WebRequest req = System.Net.WebRequest.Create(URI);
req.Proxy = new System.Net.WebProxy(ProxyString, true);

req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";

byte [] bytes = System.Text.Encoding.ASCII.GetBytes(Parameters);
req.ContentLength = bytes.Length;

System.IO.Stream os = req.GetRequestStream ();
os.Write (bytes, 0, bytes.Length);
os.Close ();

System.Net.WebResponse resp = req.GetResponse();
if (resp== null) return null;

System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
return sr.ReadToEnd().Trim();
}
暖枫无敌 2011-09-02
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 zlcp520 的回复:]

我是要模拟发送啊,不是服务器端判断啊...............
[/Quote]
那你参考这里吧
http://www.360doc.com/content/10/0711/23/19147_38380845.shtml
zlcp520 2011-09-02
  • 打赏
  • 举报
回复
我是要模拟发送啊,不是服务器端判断啊...............
zlcp520 2011-09-02
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 taomanman 的回复:]
引用 3 楼 zlcp520 的回复:

引用 2 楼 taomanman 的回复:
x-requested-with XMLHttpRequest是Ajax 异步请求方式

使用
request.getHeader("x-requested-with");
为 null,则为传统同步请求;
为 XMLHttpRequest,则为 Ajax 异步请求。


request是什……
[/Quote]

C#怎么搞啊,不会jsp
zlcp520 2011-09-02
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 hexytxl 的回复:]
在服务器端判断request来自Ajax请求(异步)还是传统请求(同步)


  在服务器端判断request来自Ajax请求(异步)还是传统请求(同步):

  两种请求在请求的Header不同,Ajax 异步请求比传统的同步请求多了一个头参数

  1、传统同步请求参数

    accept text/html,application/xhtml+xml,applic……
[/Quote]

request是什么对象?
暖枫无敌 2011-09-02
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zlcp520 的回复:]

引用 2 楼 taomanman 的回复:
x-requested-with XMLHttpRequest是Ajax 异步请求方式

使用
request.getHeader("x-requested-with");
为 null,则为传统同步请求;
为 XMLHttpRequest,则为 Ajax 异步请求。


request是什么对象?
[/Quote]
jsp中的对象
http://wenwen.soso.com/z/q215517096.htm
加载更多回复(3)

111,113

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧