標籤:
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 基礎串連已經關閉: 接收時發生錯誤