Rajveer singh

Rajveer singh

  • 800
  • 1k
  • 249k

The underlying connection was closed...

Apr 5 2018 6:57 AM
Dear all,
                   I got an error like "the underlying connection was closed a connection that was expected to be kept alive was closed by server"   when send a post request to the server by API. Getting this error alternate.  if the call with HTTP then working fine but call with HTTPS then return the same error.give me response this problem. what do I change in client side or Server side? 
 
My client code 
 
 
HttpWebRequest req = (HttpWebRequest)(HttpWebRequest.Create("https://abc.com"));
req.Method = "POST";
req.ProtocolVersion = HttpVersion.Version11;
req.ContentType = "application/xml";
req.Timeout = ResponseTimeOut;
req.Headers.Set(HttpRequestHeader.Authorization, "Basic api key");
d1 = DateTime.Now;
string content = authXMLString;
req.ContentLength = content.Length;
Stream wri = req.GetRequestStream();
byte[] array = Encoding.UTF8.GetBytes(content);
wri.Write(array, 0, array.Length);
wri.Flush();
wri.Close();
HttpWebResponse HttpWResp = (HttpWebResponse)req.GetResponse();
int resCode = (int)HttpWResp.StatusCode;
StreamReader reader = new StreamReader(HttpWResp.GetResponseStream(), System.Text.Encoding.UTF8);
string resultData = reader.ReadToEnd();
d2 = DateTime.Now;
decodedresult = resultData;
decodedresult = decodedresult.Replace("<", "<");
decodedresult = decodedresult.Replace(">", ">");
 

Answers (1)