HttpWebRequest 的 IfModifiedSince 怎么设置才等于 0
抓包得到的数据:GET/ajax/GetCount.aspx?id=0&nows=1367742955902HTTP/1.1Accept:*/*Accept-Langua...
抓包得到的数据:
GET /ajax/GetCount.aspx?id=0&nows=1367742955902 HTTP/1.1
Accept: */*
Accept-Language: zh-cn
Referer: http://127.0.0.1/index.aspx
If-Modified-Since: 0
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)
Host: 127.0.0.1
Connection: Keep-Alive
Cookie: ASP.NET_SessionId=kzcfqaa3kilah2ejlrkisf45; username=; questionId=
程序代码:
HttpWebRequest request = WebRequest.Create(" http://127.0.0.1/ajax/GetCount.aspx?id=0&nows=1367742955902") as HttpWebRequest;
request.Method = "GET";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)";
request.Accept = "*/*";
request.Headers("Accept-Language") = "zh-cn";
request.Headers("Accept-Encoding") = "gzip, deflate";
request.Referer = " http://127.0.0.1/index.aspx";
request.Headers.Add("If-Modified-Since", "0");
//这里会出现错误:System.ArgumentException: 必须使用适当的属性或方法修改“If-Modified-Since”标头。
//如果写为:request.IfModifiedSince = 这里是 Date类型 不知道怎么写才会等于 0 展开
GET /ajax/GetCount.aspx?id=0&nows=1367742955902 HTTP/1.1
Accept: */*
Accept-Language: zh-cn
Referer: http://127.0.0.1/index.aspx
If-Modified-Since: 0
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)
Host: 127.0.0.1
Connection: Keep-Alive
Cookie: ASP.NET_SessionId=kzcfqaa3kilah2ejlrkisf45; username=; questionId=
程序代码:
HttpWebRequest request = WebRequest.Create(" http://127.0.0.1/ajax/GetCount.aspx?id=0&nows=1367742955902") as HttpWebRequest;
request.Method = "GET";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)";
request.Accept = "*/*";
request.Headers("Accept-Language") = "zh-cn";
request.Headers("Accept-Encoding") = "gzip, deflate";
request.Referer = " http://127.0.0.1/index.aspx";
request.Headers.Add("If-Modified-Since", "0");
//这里会出现错误:System.ArgumentException: 必须使用适当的属性或方法修改“If-Modified-Since”标头。
//如果写为:request.IfModifiedSince = 这里是 Date类型 不知道怎么写才会等于 0 展开
展开全部
好像If-Modified-Since只允许在Request.IfModifiedSince属性上设置而且必须是日期类型,如果你要设置其他类型的话可以用反射调用WebHeaderCollection的AddInternal方法跳过Header的验证。
代码如下:
using System.Reflection;
private void button1_Click(object sender, EventArgs e)
{
HttpWebRequest request = WebRequest.Create("http://www.baidu.com/") as HttpWebRequest;
request.Method = "GET";
request.Referer = " http://127.0.0.1/index.aspx";
Type type = request.Headers.GetType();
type.InvokeMember("AddInternal", BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.NonPublic, null, request.Headers, new object[] { "If-Modified-Since", "0" });
type.InvokeMember("AddInternal", BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.NonPublic, null, request.Headers, new object[] { "Test", "123456789" });
WebResponse response = request.GetResponse();
}
2013-05-07
展开全部
DateTime dt1 = DateTime.Parse((DateTime.Now - DateTime.Now).ToString());
DateTime dt2 = DateTime.Parse("00:00:00");
datetime日期类型,需要有个精确的时间值的,一天是24小时,所返回的值最小就是上面两行代码的结果(当天0点)
DateTime dt2 = DateTime.Parse("00:00:00");
datetime日期类型,需要有个精确的时间值的,一天是24小时,所返回的值最小就是上面两行代码的结果(当天0点)
追问
像你这样写抓到的包:
If-Modified-Since: Mon, 06 May 2013 16:00:00 GMT //注意:我这里要的是 If-Modified-Since: 0
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询