HttpWebRequest.Expect的问题

qugui 2007-03-11 06:45:31
本人用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="";都不行,请高人指

点。
...全文
383 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
baseyueliang 2007-03-12
  • 打赏
  • 举报
回复
不熟悉html格式,可否先通过xml解析器形成一颗title tree?然后在处理。
tiantian1980 2007-03-12
  • 打赏
  • 举报
回复
不懂,学习

110,538

社区成员

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

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

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