首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

请高手支招啊该怎么解决

2012-03-25 
请高手支招啊。还是HttpWebRequest.Expectd在post的时候出现的问题。我在网上看到有人说这个一个BUG,地址htt

请高手支招啊。
还是HttpWebRequest.Expectd在post的时候出现的问题。


我在网上看到有人说这个一个BUG,地址http://www.dotnet247.com/247reference/msgs/31/158004.aspx
但是我用2005出来的程序一样在post的时候会出现Expect:   100-continue。
这样会比IE   post数据的时候多一个服务器响应。

我的代码改成如下的时候:
HttpWebRequest   req   =   (HttpWebRequest)WebRequest.Create(url);
                                req.PreAuthenticate   =   true;
                                req.KeepAlive   =   true;
                                req.ProtocolVersion   =   HttpVersion.Version11;
                       

                                req.Method   =   "POST ";
                                //req.Timeout   =   60000;
                                req.Accept= "image/gif,   image/x-xbitmap,   image/jpeg,   image/pjpeg,   application/vnd.ms-excel,   application/vnd.ms-powerpoint,   application/msword,   application/x-shockwave-flash,   */* ";
                                req.Referer   =   referer;
                                req.Headers.Add( "Accept-Language:   zh-cn ");
                                req.ContentType   =   "application/x-www-form-urlencoded ";
                              req.Headers.Add( "UA-CPU ",   "x86 ");
                                req.AllowAutoRedirect   =   true;
                                req.Headers.Add( "Accept-Encoding:   gzip,   deflate ");
                                req.UserAgent   =   "Mozilla/4.0   (compatible;   MSIE   6.0;   Windows   NT   5.1;   SV1;   .NET   CLR   1.1.4322) ";
                                req.Headers.Add( "Cache-Control:   no-cache ");

                                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;
                                }
                                req.KeepAlive   =   true;
                                req.Expect   =   null;
                                req.KeepAlive   =   true;

                                string[]   key1   =   req.Headers.AllKeys;
                                foreach   (string   l   in   key1)
                                {
                                        strResult   +=   l   +   ": "   +   req.Headers[l]   +   "\r\n ";
                                }
返回的header中并没有了Expect,但是服务器的还在可以从当前请求中读出Expect:   100-continue.
请高人指教啊。

我的测试网址为:http://quack.oicp.net/header.aspx,请用post   方法访问。


[解决办法]
帮LZ顶
[解决办法]
我翻下代码
[解决办法]
加上
ServicePointManager.Expect100Continue = false;
Expect: 100-continue。就没了
[解决办法]
加上这句就没有这个Expect了 代码可以改回原来的了
也不能算是bug 反正都要加这句
[解决办法]

热点排行