HttpWebRequest를 사용하여 요청하는 중 오류 발생: 기본 연결이 닫혔고 보내는 중 오류 처리

1572 단어
최근에 원래의 위챗 시뮬레이션 로그인을 디버깅할 때'기초 연결이 닫혔습니다. 발송할 때 오류가 발생했습니다'라는 오류 알림이 발생했습니다. 원래는 모두 멀쩡했지만 오랫동안 사용하지 않았습니다.
오류 코드는 다음과 같습니다.
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();


Google과 테스트를 통해 다음과 같은 간단한 답변이 추가되었습니다.
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;통과 코드는 다음과 같습니다.
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;
           ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
            HttpWebResponse res = (HttpWebResponse)req.GetResponse();
            StreamReader rd = new StreamReader(res.GetResponseStream());
            string theContent = rd.ReadToEnd();

뒤탈을 막기 위해 기록해라!

좋은 웹페이지 즐겨찾기