HttpWebRequest 基礎串連已經關閉: 接收時發生錯誤

來源:互聯網
上載者:User

標籤:

HttpWebRequest request = null;            Stream webStream = null;            HttpWebResponse response = null;            StreamReader reader = null;            string responseString = "";            try            {                byte[] bf = Encoding.UTF8.GetBytes(postString);                request = WebRequest.Create(url) as HttpWebRequest;                request.Method = "POST";                request.ServicePoint.Expect100Continue = false;                request.Timeout = 1000 * 3;                request.ContentType = "application/x-www-form-urlencoded";                request.KeepAlive = false;                request.ProtocolVersion = HttpVersion.Version11;                  request.ContentLength = bf.Length;                webStream = request.GetRequestStream();                webStream.Write(bf, 0, bf.Length);                response = (HttpWebResponse)request.GetResponse();                reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);                responseString = reader.ReadToEnd();                Log.Info(responseString);            }            catch (Exception ex)            {                throw ex;            }            finally            {                request.Abort();                request = null;                if (webStream != null)                {                    webStream.Close();                }                if (reader != null)                {                    reader.Close();                }                if (response != null)                {                    response.Close();                    response = null;                }            }                        //解析            JavaScriptSerializer jsonConvert = new JavaScriptSerializer();            dynamic responseObj = jsonConvert.DeserializeObject(responseString);            if (responseObj is Dictionary<string, object>)            {                Dictionary<string, object> jsonobj = (Dictionary<string, object>)responseObj;                message.ResponseMessage = string.Format("[{0}]"+jsonobj["ResultDesc"].ToString(),DateTime.Now.ToString());            }
View Code

 

在調試簡訊通訊介面的時候出現 “基礎串連已經關閉: 接收時發生錯誤”

研究很長時間 ,沒找到原因,尋找網上解決方案,其中一位仁兄的方案提供了協助,這裡友情串連一下:http://blog.csdn.net/liehuo123/article/details/7071636

 

總結一下原因,可能是必須指定雙方http協議相同。

網上還有其他的解決方案,如

MyRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)";

這個沒試過。

諸君如果以上方式不能解決,請請教百度君。

HttpWebRequest 基礎串連已經關閉: 接收時發生錯誤

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.