"基础连接已关闭:发送时发生意外错误." WebClient.OpenRead中的错误(字符串链接)

Myo*_*att 2 c# asp.net google-api

我面临错误"基础连接已关闭:发送时发生意外错误." 获取返回数据google API.
它本地很好,但我已经发布并上传到服务器,我遇到了错误.请帮帮我..最好的问候......

 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();
      }
Run Code Online (Sandbox Code Playgroud)

Fia*_*eid 9

您的连接正在连接到HTTPS端点,它可能需要TLS 1.2,这可能不是您客户端的默认TLS版本; 这是旧版.NET的修复:

ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
Run Code Online (Sandbox Code Playgroud)