C# HttpWebRequest The underlying connection was closed: An unexpected error occurred on a receive.
trying all the solutions but not get the solution.
OS: Windows 10 pro
server support this TLS version
1st method
- public void GET_request()
- {
- ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12
- HttpWebRequest req = (HttpWebRequest)(HttpWebRequest.Create(url));
- req.Method = "POST";
- req.KeepAlive = false;
- req.ContentType = "application/xml";
- req.ProtocolVersion = HttpVersion.Version10;
- req.Headers.Set(HttpRequestHeader.Authorization, "Basic abcd15243");
- string content = XDAuth.OuterXml;
- req.ContentLength = content.Length;
- Stream wri = null;
- using (wri = req.GetRequestStream())
- {
- byte[] array = Encoding.UTF8.GetBytes(content);
- wri.Write(array, 0, array.Length);
- }
- wri.Flush();
- wri.Close();
- string resultData = "";
- using (HttpWebResponse HttpWResp = (HttpWebResponse)req.GetResponse())
- {
- int resCode = (int)HttpWResp.StatusCode;
- using (Stream stream = HttpWResp.GetResponseStream())
- {
- using (StreamReader reader = new StreamReader(stream))
- {
- resultData = reader.ReadToEnd();
- }
- }
- }
- }
- protected override WebRequest GetWebRequest(Uri address)
- {
- WebRequest webRequest = base.GetWebRequest(address) as WebRequest;
- if (webRequest == null)
- {
- return base.GetWebRequest(address);
- }
- webRequest.Method = "POST";
- webRequest.ContentType = "Application/xml";
- webRequest.Headers.Set(HttpRequestHeader.Authorization, "Basic abcd15243");
-
- return webRequest;
- }