I have a web API that needs to communicate with several different services. I currently have the Web API installed to use the following security protocol:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
When the API calls another service through an HttpClient (e.g. Twitter), it will use this protocol. At the same time, however, a different request may be required in order to access something from the cloud, which for some reason requires TLS (and not TLS 1.2). The cloud request before starting sets the security protocol again:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
The problem I am facing is when two separate and unique requests appear: one for Twitter and one for the cloud, the security protocol may switch to the βwrongβ one before sending it, as a result of which the request will fail.
Is there a way to set the security protocol in HttpClient for each request so that I do not replace the parameter in some singleton somewhere?
Porschiey
source share