{"id":189,"date":"2021-04-12T10:48:42","date_gmt":"2021-04-12T08:48:42","guid":{"rendered":"https:\/\/www.lambrecht.de\/?p=189"},"modified":"2021-04-12T10:48:42","modified_gmt":"2021-04-12T08:48:42","slug":"remove-system-proxy-for-invoke-webrequest-and-invoke-restmethod","status":"publish","type":"post","link":"https:\/\/www.lambrecht.de\/?p=189","title":{"rendered":"Remove System Proxy for Invoke-WebRequest and Invoke-RestMethod"},"content":{"rendered":"\n<p>We recently had a problem that accessing a function app through Invoke-RestMethod with using a private endpoint failed, as the System default proxy will be queried. In Powershell 7.x there is a switch for disabling the proxy (-NoProxy) but there is none for Powershell 5.1. So we were searching on the web but actually did not find a nice solution. All were talking about using a proxy, which can be easily done with the &#8222;-proxy&#8220;-Switch, but you cannot set this to &#8222;none&#8220;. So we finally found a solution, by first creating a new WebSession, setting the proxy to nothing and then handling all upcoming Invoke-RestMethod or Invoke-WebSession with a predefined WebSession. This will override the current user-default-proxy and will then just &#8222;go local&#8220;<\/p>\n\n\n\n<p>So here it is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$Proxy=New-object System.Net.WebProxy\r\n$WebSession=new-object Microsoft.PowerShell.Commands.WebRequestSession\r\n$WebSession.Proxy=$Proxy\r\n$Answer=Invoke-RestMethod -Method Post -Uri \"https:\/\/my.restmethod.site\" -WebSession $WebSession \r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>We recently had a problem that accessing a function app through Invoke-RestMethod with using a private endpoint failed, as the System default proxy will be queried. In Powershell 7.x there is a switch for disabling the proxy (-NoProxy) but there &hellip; <a href=\"https:\/\/www.lambrecht.de\/?p=189\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,19,18],"tags":[21,26,25],"class_list":["post-189","post","type-post","status-publish","format-standard","hentry","category-allgemein","category-it","category-powershell","tag-powershell","tag-proxy","tag-restmethod"],"_links":{"self":[{"href":"https:\/\/www.lambrecht.de\/index.php?rest_route=\/wp\/v2\/posts\/189","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lambrecht.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lambrecht.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lambrecht.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lambrecht.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=189"}],"version-history":[{"count":0,"href":"https:\/\/www.lambrecht.de\/index.php?rest_route=\/wp\/v2\/posts\/189\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.lambrecht.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lambrecht.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lambrecht.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}