我遇到了错误“基础连接已关闭:发送时出现意外错误”。获取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();
}
发布于 2017-06-01 18:42:11
您的连接正在连接到HTTPS终结点,可能需要TLS1.2,这可能不是您的客户端的默认TLS版;这是旧版本.NET的修复程序:
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
发布于 2016-07-01 13:07:14
当客户端计算机无法发送
请求时,就会出现此问题。客户端计算机无法发送HTTP请求,因为连接已关闭或不可用。当客户端计算机发送大量数据时,可能会出现此问题。
访问https://support.microsoft.com/en-us/kb/915599
参见决议A、D、E、F和O可能会对您有所帮助。
更新1:
不幸的是,上面的链接断开了。请阅读以下内容。
为了适应.Net Framework4.0中的TLS1.2,可以尝试这样做:
ServicePointManager.SecurityProtocol = DirectCast(3072, SecurityProtocolType)
如果TLS 1.2不适用于您,请尝试以下方法:
System.Net.ServicePointManager.SecurityProtocol =
SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
以下是有关TLS和.NET支持的一些信息:
TLS4.6及以上版本。你不需要做任何额外的工作来支持
TLS4.5。支持TLS1.2,但它不是默认协议。你需要选择加入来使用它。以下代码将使TLS1.2成为默认代码,请确保在连接到受保护的资源之前执行该代码: SecurityProtocolType.Tls12 = ServicePointManager.SecurityProtocol
TLS1.2不受支持,但如果您在系统上安装了.NET 4.5 (或更高版本),那么即使您的应用程序框架不支持TLS1.2,您仍然可以选择使用它。唯一的问题是(SecurityProtocolType)3072; 4.0中的SecurityProtocolType没有TLS1.2条目,所以我们必须使用枚举值的数字表示: ServicePointManager.SecurityProtocol =TLS1.2
TLS3.5或更低版本。不支持
有关TLS和.NET支持的更多信息,请访问以下链接:
https://stackoverflow.com/questions/38137244
复制相似问题