I have a asp.net core 3.1 webserver that I run from Visual studio 2019 (Ctrl+F5). That has an HTTP GET endpoint which I can successfully call using REST Client in VS Code:
GET https://localhost:5001/api/myResource
Then I am trying to develop a service worker (also .net core 3.1) that I run from a console and that call's the same resource. Like so..
httpClient = new HttpClient();
var responseHTTP = await httpClient.GetAsync("https://localhost:5001/api/myResource");
The response that I then get is an error message from my company's proxy (stating forbidden access bla bla bla) and what address actually was posted (part of the response content):
While trying to retrieve the URL: localhost.mycompany.com:5001
Hence it has added
mycompany.com
to the address that I supplied in the httpClient.GetAsync()
I have tried disabling the proxy in windows setup (incl. removing environment variables) and restarted both the console and the local webserver. But still it goes through the proxy (or I get the same forbidden answer from the proxy). Is there a way to bypass the proxy? All the questions and answers I have looked at is about the opposite, getting the httpClient to use the proxy.
You can look to use something like this to disable use of the system proxy, if your HttpClient
is picking it up from the system settings:
var handler = new HttpClientHandler() { UseProxy = false };
httpClient = new HttpClient(handler);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With