Reproduced, original from http://blog.csdn.net/hawksoft/article/details/21776009
Recently debugging the original analog login occurred "The underlying connection has been closed, send an error" error, the original is good, just a long time useless.
The error code is as follows:
HttpWebRequest req = (HttpWebRequest) httpwebrequest.create ("https://mp.weixin.qq.com/cgi-bin/loginpage?t= Wxm2-login&lang=zh_cn ");///CGI-BIN/LOGINPAGE?T=WXM2-LOGIN&LANG=ZH_CN req. Cookiecontainer = cookie; Req. Method = "GET"; Req. ProtocolVersion = Httpversion.version10; HttpWebResponse res = (HttpWebResponse) req. GetResponse (); StreamReader rd = new StreamReader (res. GetResponseStream ()); string thecontent = Rd. ReadToEnd ();
After some Google and experiment, the answer is so simple, add the following sentence:
Servicepointmanager.securityprotocol = SECURITYPROTOCOLTYPE.SSL3;
Through the code is as follows:
HttpWebRequest req = (HttpWebRequest) httpwebrequest.create ("https://mp.weixin.qq.com/cgi-bin/loginpage?t= Wxm2-login&lang=zh_cn ");///cgi-bin/loginpage?t=wxm2-login&lang=zh_cn
Req. Cookiecontainer = cookie; " GET " ; = httpversion.version10; = securityprotocoltype.ssl3; = (HttpWebResponse) req. GetResponse (); New StreamReader (Res. GetResponseStream ()); string thecontent = Rd. ReadToEnd ();
[Reprint] An error occurred when making a request using HttpWebRequest: The underlying connection was closed and error handling occurred while sending