mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-20 00:03:48 +01:00
Added X509Certificate2Filename (#27)
This commit is contained in:
@@ -7,10 +7,39 @@ namespace WireMock.Http
|
||||
{
|
||||
internal static class HttpClientHelper
|
||||
{
|
||||
private static HttpClient client = new HttpClient();
|
||||
|
||||
public static async Task<ResponseMessage> SendAsync(RequestMessage requestMessage, string url)
|
||||
private static HttpClient CreateHttpClient(string clientX509Certificate2Filename = null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(clientX509Certificate2Filename))
|
||||
{
|
||||
#if NETSTANDARD || NET46
|
||||
var handler = new HttpClientHandler
|
||||
{
|
||||
ClientCertificateOptions = ClientCertificateOption.Manual,
|
||||
SslProtocols = System.Security.Authentication.SslProtocols.Tls12 | System.Security.Authentication.SslProtocols.Tls11 | System.Security.Authentication.SslProtocols.Tls,
|
||||
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true
|
||||
};
|
||||
|
||||
handler.ClientCertificates.Add(new System.Security.Cryptography.X509Certificates.X509Certificate2(clientX509Certificate2Filename));
|
||||
return new HttpClient(handler);
|
||||
#else
|
||||
var handler = new WebRequestHandler
|
||||
{
|
||||
ClientCertificateOptions = ClientCertificateOption.Manual,
|
||||
ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true
|
||||
};
|
||||
|
||||
handler.ClientCertificates.Add(new System.Security.Cryptography.X509Certificates.X509Certificate2(clientX509Certificate2Filename));
|
||||
return new HttpClient(handler);
|
||||
#endif
|
||||
}
|
||||
|
||||
return new HttpClient();
|
||||
}
|
||||
|
||||
public static async Task<ResponseMessage> SendAsync(RequestMessage requestMessage, string url, string clientX509Certificate2Filename = null)
|
||||
{
|
||||
var client = CreateHttpClient(clientX509Certificate2Filename);
|
||||
|
||||
var httpRequestMessage = new HttpRequestMessage(new HttpMethod(requestMessage.Method), url);
|
||||
|
||||
// Overwrite the host header
|
||||
|
||||
Reference in New Issue
Block a user