HttpWebRequest POST 数据时请求头多了一行Expect: 100-continue,少了数据行

用HttpWebRequest   POST数据时POST数据被截掉了。使用HTTPLook跟踪出来的HTTP头信息  
  POST   /sp/SPLogin   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,   */*  
  User-Agent:   Mozilla/4.0   (compatible;   MSIE   6.0;   Windows   NT   5.2;   SV1;   .NET   CLR   1.1.4322  
  Accept-Language:   zh-cn  
  UA-CPU:   x86  
  Accept-Encoding:   gzip,   deflate  
  Content-Type:   application/x-www-form-urlencoded  
  Content-Length:   85  
  Expect:   100-continue  
  Connection:   Keep-Alive  
  Host:   test.com  
  Cookie:   JSESSIONID=Ghdht2vhW2xTPcFRYG1ch1Xt1Kp81rRGvR11nlQNKW6l4MTZ1MHk!-1870340995  
   
  正常情况应为:  
  POST   /sp/SPLogin   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,   */*  
  User-Agent:   Mozilla/4.0   (compatible;   MSIE   6.0;   Windows   NT   5.2;   SV1;   .NET   CLR   1.1.4322  
  Accept-Language:   zh-cn  
  UA-CPU:   x86  
  Accept-Encoding:   gzip,   deflate  
  Content-Type:   application/x-www-form-urlencoded  
  Content-Length:   85  
  Connection:   Keep-Alive  
  Host:   admin.sh.monternet.com  
  Cookie:   JSESSIONID=Ghdht2vhW2xTPcFRYG1ch1Xt1Kp81rRGvR11nlQNKW6l4MTZ1MHk!-1870340995  
   
  selectAccount=SPPREREG&USER=907000&PASSWORD=111111&addCode=9146&Submit22=%B5%C7%C2%BC  
   
   
  以下是程序代码:  
  public   static   void   GetWebContent(string   url,CookieContainer   cookies,string   filename)  
  {  
        HttpWebRequest   request   =   null;  
        HttpWebResponse   response   =   null;  
        CookieCollection   cookieResponse   =   new   CookieCollection();  
        CookieContainer   cookieRequest   =   new   CookieContainer();  
        Uri   requestUri   =   new   Uri(url);  
        try  
        {  
              Cookie   cookie   =   new   Cookie();  
              cookie.Name   =   "JSESSIONID";  
              cookie.Value   =   "Ghdht2vhW2xTPcFRYG1ch1Xt1Kp81rRGvR11nlQNKW6l4MTZ1MHk!-1870340995";  
              cookie.Path   =   "/";  
              cookie.Domain   =requestUri.Host;  
              cookieRequest.Add(cookie);  
   
              //   处理请求  
              request   =   (HttpWebRequest)   WebRequest.Create(new   Uri(url));  
              request.Accept   ="image/gif,   image/x-xbitmap,   image/jpeg,   image/pjpeg,   application/vnd.ms-excel,   application/vnd.ms-powerpoint,   application/msword,   application/x-shockwave-flash,   */*";  
              request.UserAgent   =   "Mozilla/4.0   (compatible;   MSIE   6.0;   Windows   NT   5.2;   SV1;   .NET   CLR   1.1.4322";  
              request.Headers.Add("Accept-Language:   zh-cn");  
              request.Headers.Add("UA-CPU:   x86");  
              request.Headers.Add("Accept-Encoding:   gzip,   deflate");  
              request.Timeout   =   20000;  
              request.CookieContainer   =   cookieRequest;  
   
              string   data   =   "selectAccount=SPPREREG&USER=907000&PASSWORD=111111&addCode=9146&Submit22=%B5%C7%C2%BC";  
              byte[]   byteData   =   Encoding.Default.GetBytes(data);  
              request.Method   ="POST";  
              request.ContentType   =   "application/x-www-form-urlencoded";  
              request.ContentLength   =   byteData.Length;  
              using   (Stream   requestStream   =   request.GetRequestStream())  
              {  
  requestStream.Write(byteData,0,byteData.Length);  
              }  
   
              //   处理响应  
              response   =   (HttpWebResponse)request.GetResponse();  
              cookieResponse   =   response.Cookies   ;  
              byte[]   buffer   =     ResponseAsBytes(response);  
              response.Close();  
   
              FileStream   file   =   new   FileStream(filename,   FileMode.Create);  
              file.Write(buffer,0,buffer.Length);  
   
         
        }catch(Exception   ex)  
        {  
              Log.Error("GetWeb:Url="+url   +   ex.Message,ex);  
        }  
  }  
  那位知道原因吗??  



自己已经搞定,设置一个属性  
  request.ServicePoint.Expect100Continue   =   false;   
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值