平均售价净"The underlying connection was closed: An unexpected error occurred on a send."



面临一个非常奇怪的问题。生产服务器上的程序向googleapi发送一个get请求。我得到错误";基础连接已关闭:发送时发生意外错误">

操作系统:Windows Server 2008 R2 SP1

IIS 7

启用TLS 1.0/1.1/1.2、SSL 2.0/3.0

.Net Framework 4.8

URL";https://googleapi.com"添加到";可信站点";列出

此URL在IE中打开。它在一台正常工作的电脑上(以及我所有其他电脑上(都能正常工作。问题仅出现在生产服务器上。

也许有人遇到过这样的事情,会告诉我在这种情况下该在哪里找到解决方案?

测试代码:

string url = $"https://www.googleapis.com/analytics/v3/data/ga";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

using (WebResponse response = request.GetResponse())
{
using (Stream responseStream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(responseStream);
string result = reader.ReadToEnd();
reader.Close();
Console.WriteLine($"nn{result}nn");
}
}

例外:

System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> Syste
m.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the r
emote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncReq
uest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncReq
uest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncReq
uest)
at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRe
quest)
at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object
state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, B
oolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result)
at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.ConnectStream.WriteHeaders(Boolean async)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetResponse()
at GoogleFetchTest.Program.Main(String[] args)

这是一个与协议(TLS协议(有关的问题。在呼叫服务之前使用以下解决方案应该可以解决问题,

ServicePointManager.SecurityProtocol|=SecurityProtocolType.Tls12

感谢大家!SSL 2.0/3.0包含在互联网选项中并添加url";https://www.gogleapis.com"到受信任的站点。

互联网选项Sreenshot

相关内容

  • 没有找到相关文章

最新更新