Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"The underlying connection was closed: An unexpected error occurred on a send." Error in WebClient.OpenRead(string link)

I am facing the Error "The underlying connection was closed: An unexpected error occurred on a send." in getting return data of google API.
It was fine locally but I had published and upload to server, I faced that Error. Help me please.. Best Regard...

 WebClient webClient = new WebClient();
 Stream stream = webClient.OpenRead("https://www.googleapis.com/oauth2/v1/userinfo?access_token=[Access_Token]);
 string b;

/*I have not used any JSON parser because I do not want to use any extra dll/3rd party dll*/
 using (StreamReader br = new StreamReader(stream))
      {
         b = br.ReadToEnd();
      }
like image 555
mmz Avatar asked Dec 18 '25 22:12

mmz


1 Answers

Your connection is connecting to a HTTPS endpoint, it may be possible that it requires TLS 1.2, which may not be the default TLS version of your client; this is a fix for older versions of .NET:

ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
like image 196
Fiach Reid Avatar answered Dec 20 '25 11:12

Fiach Reid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!