I have created an Excel VSTO Add-In, which connects to an API using IdentityModel to get a token and to send and receive data from a website. This has worked quite well, until a couple of days ago. On Windows 7 environments I get the message
An error occurred while sending the request. The underlying connection was closed: An unexpected error occurred on a send.
because tokenResponse.HttpStatusCode = 0
The full message is Error during login: 0: An error occurred while sending the request.
This error does not appear on Windows 10 environments.
What changed in the previous days was that the website has disabled certain ciphers, because SSLlabs said they were to weak to give the site an A+ rating. It is for instance not possible anymore to access the website by using IE11 on Windows 7, but it is possible to use IE11 on Windows 10.
My code to get the accesstoken is as follows:
Imports IdentityModel.Client
Imports System.Net.Http
Function Login(weblink As String, username As String, password As String) As String
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
Try
Dim tokenClient As New HttpClient()
Dim tokenResponse As TokenResponse = tokenClient.RequestPasswordTokenAsync(New PasswordTokenRequest With {.ClientId = "clientid", .Address = weblink & "/connect/token", .UserName = username, .Password = password, .Scope = "scope", .GrantType = "password"}).Result
If tokenResponse.HttpStatusCode = System.Net.HttpStatusCode.OK Then
Return tokenResponse.AccessToken
Else
MsgBox("Error during login: " & tokenResponse.HttpStatusCode & ": " & tokenResponse.Exception.Message & " " & tokenResponse.Exception.InnerException.Message)
Return ""
End If
Catch ex As Exception
MsgBox("Error during login: " & ex.Message)
Return ""
End Try
End function
This codes worked perfectly and still works perfectly on Windows 10. I thought that the HttpClient would use somekind of default cipher suite which is not allowed anymore and I thought that maybe there would be a way of forcing the HttpClient to use an allowed cipher suite, but I haven't found anything yet.
Does someone have any idea how I can solve this? I would be very grateful!