HttpWebRequest.Expect的问题

qugui qugui 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
本人用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="";都不行,请高人指

点。
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
qugui
C# 111,128 成员 642,537 内容