Is it possible to use WireMock as a proxy server for HTTPS requests? #548

Closed
opened 2025-12-29 15:26:43 +01:00 by adam · 8 comments
Owner

Originally created by @robvangeloven on GitHub (Oct 11, 2023).

Originally assigned to: @StefH on GitHub.

So I have a use case where I'm stuck with a hardcoded URL embedded in an external SDK. There is no way for me to change that behaviour and I do need to verify the output somehow for my current use case.

I though to myself: what if I make WireMock the default proxy server? And that does work, but only for HTTP calls. HTTPS calls get a

System.Net.Http.HttpRequestException : The SSL connection could not be established, see inner exception.
    ---- System.Security.Authentication.AuthenticationException : Cannot determine the frame size or a corrupted frame was received.

However, if I remove the WireMock-as-proxy setting and make the call directly it works just fine. Only I have trouble figuring out why this is.

var wireMockServer = WireMockServer.Start(new WireMockServerSettings
  {
      Urls = new[] { "http://localhost:9091", "https://localhost:9443" },
      UseSSL = true,
  });

  // If I remove the DefaultProxy setting everything works just fine
  HttpClient.DefaultProxy = new WebProxy
  {
      Address = new Uri(wireMockServer.Url!),
      BypassProxyOnLocal = false,
  };

  wireMockServer
      .Given(Request.Create())
      .RespondWith(
          Response.Create()
          .WithStatusCode(200)
          .WithBody(@"{ ""msg"": ""Hello world!"" }"));
 
  var result = await new HttpClient().PostAsync(wireMockServer.Urls[1], null);
Originally created by @robvangeloven on GitHub (Oct 11, 2023). Originally assigned to: @StefH on GitHub. So I have a use case where I'm stuck with a hardcoded URL embedded in an external SDK. There is no way for me to change that behaviour and I do need to verify the output somehow for my current use case. I though to myself: what if I make WireMock the default proxy server? And that does work, but only for HTTP calls. HTTPS calls get a ``` System.Net.Http.HttpRequestException : The SSL connection could not be established, see inner exception. ---- System.Security.Authentication.AuthenticationException : Cannot determine the frame size or a corrupted frame was received. ``` However, if I remove the WireMock-as-proxy setting and make the call directly it works just fine. Only I have trouble figuring out why this is. ```csharp var wireMockServer = WireMockServer.Start(new WireMockServerSettings { Urls = new[] { "http://localhost:9091", "https://localhost:9443" }, UseSSL = true, }); // If I remove the DefaultProxy setting everything works just fine HttpClient.DefaultProxy = new WebProxy { Address = new Uri(wireMockServer.Url!), BypassProxyOnLocal = false, }; wireMockServer .Given(Request.Create()) .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(@"{ ""msg"": ""Hello world!"" }")); var result = await new HttpClient().PostAsync(wireMockServer.Urls[1], null); ```
adam added the question label 2025-12-29 15:26:43 +01:00
adam closed this issue 2025-12-29 15:26:43 +01:00
Author
Owner

@PG-RichT commented on GitHub (Oct 12, 2023):

@robvangeloven I'd be interested to see a response to this as I find myself in the same position. This wouldn't happen to be the Adyen SDK by any chance?

@PG-RichT commented on GitHub (Oct 12, 2023): @robvangeloven I'd be interested to see a response to this as I find myself in the same position. This wouldn't happen to be the Adyen SDK by any chance?
Author
Owner

@robvangeloven commented on GitHub (Oct 12, 2023):

@robvangeloven I'd be interested to see a response to this as I find myself in the same position. This wouldn't happen to be the Adyen SDK by any chance?

Buckaroo, so same difference really 😅

@robvangeloven commented on GitHub (Oct 12, 2023): > @robvangeloven I'd be interested to see a response to this as I find myself in the same position. This wouldn't happen to be the Adyen SDK by any chance? Buckaroo, so same difference really 😅
Author
Owner

@StefH commented on GitHub (Oct 12, 2023):

When calling the https endpoint from WireMock.Net via Postman (SSL certificate verification= true), does that work ?

And maybe these pages can help you?

@StefH commented on GitHub (Oct 12, 2023): When calling the https endpoint from WireMock.Net via Postman (SSL certificate verification= true), does that work ? And maybe these pages can help you? - https://github.com/WireMock-Net/WireMock.Net/wiki/Using-HTTPS-%28SSL%29 - https://github.com/WireMock-Net/WireMock.Net/wiki/Settings#certificatesettings
Author
Owner

@robvangeloven commented on GitHub (Oct 12, 2023):

When calling the https endpoint from WireMock.Net via Postman (SSL certificate verification= true), does that work ?

And maybe these pages can help you?

I haven't tested it via Postman, mostly because the code works just fine if I don't point the default httpclient proxy to the WireMock instance. If WireMock is configured to be the default proxy though (no other changes). I get weird SSL errors.

See also the code I linked: if I remove the

HttpClient.DefaultProxy = new WebProxy
  {
      Address = new Uri(wireMockServer.Url!),
      BypassProxyOnLocal = false,
  };

Everything works just fine. With it: SSL errors. HTTP calls work fine in both cases by the way.

@robvangeloven commented on GitHub (Oct 12, 2023): > When calling the https endpoint from WireMock.Net via Postman (SSL certificate verification= true), does that work ? > > And maybe these pages can help you? > > * https://github.com/WireMock-Net/WireMock.Net/wiki/Using-HTTPS-%28SSL%29 > * https://github.com/WireMock-Net/WireMock.Net/wiki/Settings#certificatesettings I haven't tested it via Postman, mostly because the code works just fine if I don't point the default httpclient proxy to the WireMock instance. If WireMock is configured to be the default proxy though (no other changes). I get weird SSL errors. See also the code I linked: if I remove the ```csharp HttpClient.DefaultProxy = new WebProxy { Address = new Uri(wireMockServer.Url!), BypassProxyOnLocal = false, }; ``` Everything works just fine. With it: SSL errors. HTTP calls work fine in both cases by the way.
Author
Owner

@StefH commented on GitHub (Oct 14, 2023):

@robvangeloven
I'm able to reproduce your issue (https://github.com/WireMock-Net/WireMock.Net/pull/1010), however I do not have any idea on the root cause.

@StefH commented on GitHub (Oct 14, 2023): @robvangeloven I'm able to reproduce your issue (https://github.com/WireMock-Net/WireMock.Net/pull/1010), however I do not have any idea on the root cause.
Author
Owner

@StefH commented on GitHub (Oct 14, 2023):

@robvangeloven / @PG-RichT

After some investigating I now understand what you are trying to to.

However, configuring WireMock.Net to act as a proxy-server is possible. For this purpose you should use a different solution / NuGet.

@StefH commented on GitHub (Oct 14, 2023): @robvangeloven / @PG-RichT After some investigating I now understand what you are trying to to. However, configuring WireMock.Net to act as a proxy-server is possible. For this purpose you should use a different solution / NuGet.
Author
Owner

@StefH commented on GitHub (Oct 14, 2023):

https://github.com/WireMock-Net/WireMock.Net/pull/1010

@StefH commented on GitHub (Oct 14, 2023): https://github.com/WireMock-Net/WireMock.Net/pull/1010
Author
Owner

@robvangeloven commented on GitHub (Oct 17, 2023):

@PG-RichT / anyone reading this: the FryProxy or BenderProxy could help as a MITM proxy your solution

@robvangeloven commented on GitHub (Oct 17, 2023): @PG-RichT / anyone reading this: the [FryProxy](https://github.com/eger-geger/FryProxy ) or [BenderProxy](https://github.com/jimevans/BenderProxy) could help as a MITM proxy your solution
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#548