Does powershell Invoke-RestMethod/Invoke-WebRequest ignore the proxy argument when the target is localhost?

It looks like powershell's (7.2.0, Windows 10.0.19043) Invoke-RestMethod/Invoke-WebRequest ignore the proxy argument when the target is localhost. curl does not. I am trying to pass requests through the Burp suite but if the server I'm targeting is on localhost, nothing is intercepted (but with curl it is).

Not only is the request not intercepted but apparently powershell does no error check either:

"invoke-webrequest -proxy hahawrong"

.. will give an error if I target a server that's not my own machine but not if it is localhost.

I have looked at the proxy settings for my machine and I get no difference whatever I do there (deselect "Automatically detect settings", trying "Manual proxy setup", etc) and the "Don't use proxy for local adresses" is not and has never been selected.

Finally, I see identical behavior (both powershell and curl) on two different Windows machines.

Can anyone explain why this is and how to change it so that requests from powershell do use the proxy also when the target is localhost?

Thanks


The explanation may be found in an old Fiddler article:
Problem: Traffic sent to http://localhost or http://127.0.0.1 is not captured.

Internet Explorer and the .NET Framework are hardcoded not to send requests for Localhost through any proxies, and as a proxy, Fiddler will not receive such traffic.

The simplest workaround is to use your machine name as the hostname instead of Localhost or 127.0.0.1. So, for instance, rather than hitting http://localhost:8081/mytestpage.aspx, instead visit http://machinename:8081/mytestpage.aspx.

Another workaround you may try is instead of using localhost to use: localhost. by adding a dot at the end.