Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, I get always that error "The underlying connection was closed: An unexpected error occurred on a send" when I try to invoke the REST service by GET method. (The service Respond in JSON Format)

this is my code:

C#
string uri = "https://vvzerlgggk.execute-api.us-east-1.amazonaws.com/dev/api/efecty/payment/a1b2c3d4c5f6";
            
System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);

HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);

webRequest.KeepAlive = false;
webRequest.Method = "GET";
string hmac = "rDQ2ExmsC88zcpbT7nLu864U0hvOVx974FFfqqzP"; 
webRequest.Headers.Add("x-api-keys", hmac);
//webRequest.Timeout = 60 * 1000;

HttpWebResponse response;
            
try
{
     response = (HttpWebResponse)webRequest.GetResponse();
     StreamReader reader = new StreamReader(response.GetResponseStream());
     string body = reader.ReadToEnd();
}

catch (WebException wex)
{
     response = (HttpWebResponse)wex.Response;     
} 


What do you think could I improve?

Thanks
Posted
Updated 17-Dec-19 23:57pm

1 solution

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3 | System.Net.SecurityProtocolType.Tls12;


Try the above code before sending the request it will work ...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900