我有一项服务已经在 Windows 服务器上成功运行(并且仍然)多年。
客户希望容量加倍,因此希望它在第二台 Windows 服务器上运行。然而,它失败了。
失败的部分是从 Microsoft Online 检索不记名令牌。
第二个服务器已被确认能够在 Soap UI 中执行此操作
报告异常的症结在于这个
System.AggregateException: One or more errors occurred.
---> System.Net.Http.HttpRequestException: An error occurred while sending the request.
---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.
---> System.ComponentModel.Win32Exception: The client and server cannot communicate
, because they do not possess a common algorithm
失败的函数是这个 - 它是 VB.NET(别问...)
Public Async Function GenerateAccessToken(baseURL As String, authorization As String, clientID As String, clientSecret As String, resource As String) As Task(Of String)
Dim responseString As String
Try
Dim client As HttpClient = HeadersForAccessTokenGenerate(baseURL, authorization)
Dim body As String = ""
Dim request As HttpRequestMessage = New HttpRequestMessage(HttpMethod.Post, client.BaseAddress)
request.Content = New StringContent(body, Encoding.UTF8, "application/x-www-form-urlencoded")
Dim postData As List(Of KeyValuePair(Of String, String)) = New List(Of KeyValuePair(Of String, String))()
postData.Add(New KeyValuePair(Of String, String)("grant_type", "client_credentials"))
postData.Add(New KeyValuePair(Of String, String)("client_id", clientID))
postData.Add(New KeyValuePair(Of String, String)("client_secret", clientSecret))
postData.Add(New KeyValuePair(Of String, String)("resource", resource))
request.Content = New FormUrlEncodedContent(postData)
Dim tokenResponse As HttpResponseMessage = client.PostAsync(baseURL, New FormUrlEncodedContent(postData)).Result
responseString = Await tokenResponse.Content.ReadAsStringAsync()
Catch ex As HttpRequestException
Throw ex
End Try
'Return If(responseString.Contains("error"), responseString, token.AccessToken)
Return (responseString)
End Function
重申一下 - 该代码在一台服务器上成功,但在另一台服务器上失败,并且它在 SoapUI 中都适用。
我只能向客户询问问题,并且无法直接访问服务器,因此我必须相信客户的话,即服务器配置相同。
我可以让他们检查哪些事情?
我可能已经解决了这个问题。我暂时无法与顾客核实,但还是插队了
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls13
在我的开发系统上重现了他们的错误,所以我猜测
两台服务器的 System.Net.SecurityProtocolType.SystemDefault 实际上是不同的。
所有可能的值
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12
让它在我的开发电脑上再次运行。
我发布此内容是因为它可能对其他人有帮助。