当前位置: 代码迷 >> .NET Framework >> dll中封装好的函数HttpWebRequest请求网页老是 connection:close
  详细解决方案

dll中封装好的函数HttpWebRequest请求网页老是 connection:close

热度:92   发布时间:2016-05-01 23:39:04.0
dll中封装好的函数HttpWebRequest请求网页总是 connection:close
如题在dll中封装好的函数请求一个网址,抓包显示  connection:close

导致获取不到网页内容,异常退出
dll代码如下:

StreamReader sr = null;
            HttpWebResponse response = null;
            HttpWebRequest request = null;
            Stream instream = null;
            CkCollect = null;
            Encoding encoding = Encoding.UTF8; ;
            string content = "";
            Waiturl += ConvertDateTimeInt(DateTime.Now);
            try
            {
               
                Waiturl = Waiturl.Replace("TempTime", "1393299987118");
                request = WebRequest.Create(Waiturl) as HttpWebRequest;
                request.Timeout = 10000;
                request.Accept = "*/*";
                request.KeepAlive = true;
                request.UserAgent = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.11 Safari/537.36";
                request.Referer = referurl;
                request.Headers.Add("Accept-Encoding", "gzip,deflate,sdch");
                request.Headers.Add("Accept-Charset", "GBK,utf-8;q=0.7,*;q=0.3");
                request.Headers.Add("Accept-Language", "zh-CN,zh;q=0.8");
                request.CookieContainer = ck;
                response = (HttpWebResponse)request.GetResponse();
                instream = response.GetResponseStream();
                if (response.ContentEncoding != null && response.ContentEncoding.Equals("gzip", StringComparison.InvariantCultureIgnoreCase))
                    sr = new StreamReader(new GZipStream(instream, CompressionMode.Decompress), encoding);
                else
                    sr = new StreamReader(response.GetResponseStream(), encoding);
                content = sr.ReadToEnd();

------解决方案--------------------
Waiturl  用ie访问看看
  相关解决方案