HttpWebRequest 、HttpWebResponse返回内容太多(duō)時,基礎連接已經關閉: 接收時發生錯誤。經過多(duō)種情況分(fēn)析排查後,解決方案參考如下
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl)); webReq.Method = "POST"; webReq.ContentType = "application/x-www-form-urlencoded"; webReq.Accept = "*/*"; webReq.KeepAlive = false; //重點注意此參數 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();