HttpWebRequest request =NULL; Stream Webstream=NULL; HttpWebResponse Response=NULL; StreamReader Reader=NULL; stringResponsestring =""; Try { byte[] bf =Encoding.UTF8.GetBytes (poststring); Request= WebRequest.Create (URL) asHttpWebRequest; Request. Method="POST"; Request. Servicepoint.expect100continue=false; Request. Timeout= +*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=NewStreamReader (response. GetResponseStream (), Encoding.UTF8); Responsestring=Reader. ReadToEnd (); Log.info (responsestring); } Catch(Exception ex) {Throwex; } finally{request. Abort (); Request=NULL; if(Webstream! =NULL) {webstream.close (); } if(Reader! =NULL) {reader. Close (); } if(Response! =NULL) {Response. Close (); Response=NULL; } } //parsingJavaScriptSerializer JsonConvert =NewJavaScriptSerializer (); Dynamic Responseobj=Jsonconvert.deserializeobject (responsestring); if(Responseobj isdictionary<string,Object>) {Dictionary<string,Object> jsonobj = (dictionary<string,Object>) Responseobj; Message. Responsemessage=string. Format ("[{0}]"+jsonobj["Resultdesc"]. ToString (), DateTime.Now.ToString ()); }
View Code
"The underlying connection has been closed: An error occurred while receiving" when debugging the SMS Communication interface
Research for a long time, did not find the reason, find online solutions, one of the programs provided help, here Friendship Link: http://blog.csdn.net/liehuo123/article/details/7071636
To summarize the reason, it may be necessary to specify the same HTTP protocol for both parties.
There are other solutions on the web, such as
Myrequest.useragent = "mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2;. NET CLR 1.0.3705;) ";
This has not been tried.
Gentlemen if the above way can not solve, please ask Baidu June.
HttpWebRequest The underlying connection has been closed: An error occurred while receiving