HttpWebRequest.Expect的问题
本人用HttpWebRequest登陆网页代码如下:
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
req.KeepAlive=true;
req.ContentType = "application/x-www-form-urlencoded";
req.AllowAutoRedirect = true;
req.Referer=referer;
req.Accept="image/gif, image/x-xbitmap, image/jpeg,
image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-
powerpoint, application/msword, */*";
req.UserAgent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
5.1; SV1; .NET CLR 1.1.4322)";
CookieContainer cookieCon = new CookieContainer();
req.CookieContainer = cookieCon;
req.CookieContainer.Add(new Uri(url),MyCookieColl);
StringBuilder UrlEncoded = new StringBuilder();
Char[] reserved = {'?', '=', '&'};
byte[] SomeBytes = null;
if (paramList != null)
{
int i=0, j;
while(i<paramList.Length)
{
j=paramList.IndexOfAny(reserved, i);
if (j==-1)
{
UrlEncoded.Append
(HttpUtility.UrlEncode(paramList.Substring(i, paramList.Length-i)));
break;
}
UrlEncoded.Append(HttpUtility.UrlEncode
(paramList.Substring(i, j-i)));
UrlEncoded.Append(paramList.Substring(j,1));
i = j+1;
}
SomeBytes = Encoding.UTF8.GetBytes
(UrlEncoded.ToString());
req.ContentLength = SomeBytes.Length;
Stream newStream = req.GetRequestStream();
newStream.Write(SomeBytes, 0, SomeBytes.Length);
newStream.Close();
}
else
{
req.ContentLength = 0;
}
其中并没有指定Expect值,但是用抓包工具得到如下:
POST ****************HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel,
application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*
Referer: http://*************
Accept-Language: zh-cn
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; .NET CLR 1.1.4322)
Cache-Control: no-cache
Content-Length: 125
Expect: 100-continue
Host: ***.com
现在我不想要那个Expect: 100-continue出现,试了req.Expect=null,req.Expect="";都不行,请高人指
点。
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
req.KeepAlive=true;
req.ContentType = "application/x-www-form-urlencoded";
req.AllowAutoRedirect = true;
req.Referer=referer;
req.Accept="image/gif, image/x-xbitmap, image/jpeg,
image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-
powerpoint, application/msword, */*";
req.UserAgent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
5.1; SV1; .NET CLR 1.1.4322)";
CookieContainer cookieCon = new CookieContainer();
req.CookieContainer = cookieCon;
req.CookieContainer.Add(new Uri(url),MyCookieColl);
StringBuilder UrlEncoded = new StringBuilder();
Char[] reserved = {'?', '=', '&'};
byte[] SomeBytes = null;
if (paramList != null)
{
int i=0, j;
while(i<paramList.Length)
{
j=paramList.IndexOfAny(reserved, i);
if (j==-1)
{
UrlEncoded.Append
(HttpUtility.UrlEncode(paramList.Substring(i, paramList.Length-i)));
break;
}
UrlEncoded.Append(HttpUtility.UrlEncode
(paramList.Substring(i, j-i)));
UrlEncoded.Append(paramList.Substring(j,1));
i = j+1;
}
SomeBytes = Encoding.UTF8.GetBytes
(UrlEncoded.ToString());
req.ContentLength = SomeBytes.Length;
Stream newStream = req.GetRequestStream();
newStream.Write(SomeBytes, 0, SomeBytes.Length);
newStream.Close();
}
else
{
req.ContentLength = 0;
}
其中并没有指定Expect值,但是用抓包工具得到如下:
POST ****************HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel,
application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*
Referer: http://*************
Accept-Language: zh-cn
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; .NET CLR 1.1.4322)
Cache-Control: no-cache
Content-Length: 125
Expect: 100-continue
Host: ***.com
现在我不想要那个Expect: 100-continue出现,试了req.Expect=null,req.Expect="";都不行,请高人指
点。
...全文
相关推荐
HttpWebRequest和HttpWebResponse用法小结
在每个系统出写入报告错误代码(找个合理的理由,比如系统免费升级) -> 自家服务器接收并处理错误报告 -> 反馈用户(解决掉BUG就行,不要太声扬)
C#获取网页源代码的方法
主要介绍了C#获取网页源代码的方法,涉及C#基于自定义函数读取网页html代码的方法,具有一定参考借鉴价值,需要的朋友可以参考下
HttpWebRequest实现下载图片至本地
主要为大家详细介绍了HttpWebRequest实现下载图片至本地,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
C#源码网络操作普通下载
C#源码网络操作普通下载
matlab与python SOCKET通信——UDP方法与TCP方法
前言 UDP方法 tcp方法前言 目前的正在做的项目是打算把ARM端的数据传到PC上好做算法,考虑的方案是ARM使用python,PC端使用matlab,用TCP或者UDP协议传输,先写了几个简单的例程,试了试效果,中途遇到了一些问题,本来关于python和matlab之间的网络通信的资料就挺少的,所以在博客上记录一下(需要注意,我这里的python使用的是3.5,所以在语法上和2.7略有不同,比


