Invoke-WebRequest Proxy Bypass

2020-03-30 06:00发布

How to bypass the default proxy in Windows while accessing a locally accessible URL?

By default the Invoke-WebRequest powershell cmdlet is using the default proxy server. In my setup the proxy allows only certain URLs and the locally accessible URL is not in that list.

Is there a way to bypass the proxy? I can add the URL to the proxy allowed list but I don't want to do that.

Thanks for the attention.

1条回答
Anthone
2楼-- · 2020-03-30 06:36

You can programmatically bypass proxy for local addresses and even return the old bypass list after you are done.

My function proxy will let you do that. Add your domain or server name or its IP address to override list:

   $p = proxy
   $p.Override += "*.domain.com" 
   $p | proxy
   Invoke-WebRequest ...
   #you could return old override here.

Otherwise, I think this should work:

 $proxy = new-object System.Net.WebProxy
 Invoke-WebRequest -Proxy $proxy ...
查看更多
登录 后发表回答