在 System.Net.HttpWebRequest.GetResponse() 情况下出现的。
大部分都不出。偶尔会出这个 是为什么呢

解决方案 »

  1.   

    少关键参数了另外查查ContentType是否正确。GET/POST是否用窜
      

  2.   

    谢谢,指教,我确实没给设置 ContentType
      

  3.   

    另外 请教,我使用非静态方法 会不会有什么影响,                HttpWebRequest httpWebRequest = null;
                    try
                    {
                        httpWebRequest = (HttpWebRequest)WebRequest.Create(new Uri(url));
                        httpWebRequest.UserAgent = this._reqUserAgent;
                        httpWebRequest.CookieContainer = this._cc;
                        httpWebRequest.Referer = referer;
                        httpWebRequest.Accept = this._accept;
                        httpWebRequest.Method = "GET";
                        httpWebRequest.Timeout = 20000;
                        httpWebRequest.UnsafeAuthenticatedConnectionSharing = true;                    string html = "";
                        using (httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse())
                        {
                            using (System.IO.StreamReader read = new System.IO.StreamReader(httpWebResponse.GetResponseStream(), encode))
                            {
                                html = read.ReadToEnd();
                            }
                            httpWebResponse.Close();
                        }
                        return html;
                    }
    只是我的部分代码。忘指教
      

  4.   

    厄光看这段代码没啥问题。不过这段代码处理不了返回是 GZip 压缩的流,提醒一下。
      

  5.   

    你是指有的网站用GZIP压缩处理了吧?那需要如何处理。
    还有就是,一会可以,一会提示不行,有的机器一直可以。有的机器就偶尔不行
      

  6.   

    多线程的情况下, ServicePointManager.DefaultConnectionLimit 默认是2,需要改大。
    否则会TimeoutGZip的情况,判断Response.ContentType,然后下面代码处理。
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    string result = "";
    using(Stream streamReceive = response.GetResponseStream())
    {
        using(GZipStream zipStream = new GZipStream(streamReceive, CompressionMode.Decompress))
            using (StreamReader sr = new StreamReader(zipStream, encoding))
                result = sr.ReadToEnd();
    }
      

  7.   

    你指的是这个属性吧?httpWebRequest.ServicePoint.ConnectionLimit = 200;就是中间 多了层GZipStream把,如果是普通数据 用了这个会受影响吗? 
      

  8.   

    不是Gzip的当然不要解压。判断下Response.ContentType分开处理。
      

  9.   

    请求被中止: 连接被意外关闭。在 System.Net.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32 size)
       在 System.IO.StreamReader.ReadBuffer()
       在 System.IO.StreamReader.ReadToEnd()
    为什么 为什么?
      

  10.   

    lz真是十万个为什么哈。问题整理下,一次问出来不好么?另外你贴个代码片段,别人怎么分析?建议下个Fiddler,抓包分析下。有问题和没问题的信息对比分析。