HttpWebRequest The underlying connection has been closed: An error occurred while receiving

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.