分享最實(shí)用的技術(shù),創(chuàng)造更大的價(jià)值

HttpWebRequest HttpWebResponse 返回大量數(shù)據(jù)無法接收解決方案

HttpWebRequest 、HttpWebResponse返回內(nèi)容太多時(shí),基礎(chǔ)連接已經(jīng)關(guān)閉: 接收時(shí)發(fā)生錯(cuò)誤。經(jīng)過多種情況分析排查后,解決方案參考如下

                HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl));
                webReq.Method = "POST";
                webReq.ContentType = "application/x-www-form-urlencoded";

                webReq.Accept = "*/*";
                webReq.KeepAlive = false; //重點(diǎn)注意此參數(shù)
                webReq.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);

                webReq.ContentLength = byteArray.Length;
                Stream newStream = webReq.GetRequestStream();
                newStream.Write(byteArray, 0, byteArray.Length);
                newStream.Close();

                HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
                StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                string _Result = sr.ReadToEnd();



聯(lián)系
QQ
電話
咨詢電話:189-8199-7898
TOP