Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bypass proxy when HTTPGET https://localhost/

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.

like image 524
Erik Thysell Avatar asked Sep 01 '25 20:09

Erik Thysell


1 Answers

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);
like image 175
Caius Jard Avatar answered Sep 03 '25 16:09

Caius Jard