title: Powershell-command Invoke-webrequest login form hangs
body: <p>Using Powershell 5.0.10586.117 I want to request a specific web-site (on IIS 8.5) containing a form to log-in. Here is the specific code:</p>
  
  <pre><code>$Url = Invoke-Webrequest -Uri "https://not-work/hello.aspx" -SessionVariable SesVar
  $UrlForm = $Url.Forms[0]
  </code></pre>
  
  <p>When doing so Powershell hangs and never returns anything as long as I do not interrupt manually.</p>
  
  <p>Using </p>
  
  <pre><code>$Url = Invoke-Webrequest -Verbose -Uri "https://not-work/hello.aspx" -SessionVariable SesVar
  </code></pre>
  
  <p>I can see the following error:</p>
  
  <blockquote>
    <p>VERBOSE: Get <a href="https://not-work/hello.aspx" rel="nofollow noreferrer">https://not-work/hello.aspx</a> with 0-byte payload.</p>
  </blockquote>
  
  <p>Running the same website in Google Chrome 55.0.2883.87 it works. Using an older version of the application code on a different (likely older IIS) it works too in Powershell.</p>
  
  <p>So I am wondering, if this issue has to do with this <a href="https://connect.microsoft.com/PowerShell/feedbackdetail/view/1557783/invoke-webrequest-hangs-in-some-cases-unless-usebasicparsing-is-used" rel="nofollow noreferrer">bug</a> in Powershell?</p>
  
  <p>Note: Even when using </p>
  
  <pre><code>$Url = Invoke-Webrequest -UseBasicParsing -Verbose -Uri "https://not-work/hello.aspx" -SessionVariable SesVar
  </code></pre>
  
  <p>it fails.</p>
  
  <p>For the sake of completeness, <em>curl</em> also gives an HTTP status code 200 (like in Chrome), but there are some differences in comparison to the working version:</p>
  
  <p><strong>Non-working website</strong></p>
  
  <pre><code>C:\Tools\curl&gt;curl -k https://not-work/hello.aspx -I HTTP/1.1 200 OK
  Cache-Control: private 
  Content-Length: 12671 
  Content-Type: text/html; charset=utf-8 
  Server: Microsoft-IIS/8.5 X-AspNet-Version: 4.0.30319
  Set-Cookie: __AntiXsrfToken=d438e79fe7004ad09d950a3b8b4e507d; path=/; HttpOnly
  Set-Cookie: .ASPXAUTH=; expires=Mon, 11-Oct-1999 22:00:00 GMT; path=/; HttpOnly 
  X-Powered-By: ASP.NET 
  Date: Thu, 12 Jan 2017 13:57:33 GMT
  </code></pre>
  
  <p><strong>Working website</strong></p>
  
  <pre><code>C:\Tools\curl&gt;curl -k https://works-well/hello.aspx -I HTTP/1.1 200 OK
  Cache-Control: private  Content-Length: 12306 Content-Type: text/html; charset=utf-8  
  X-Frame-Options: SAMEORIGIN 
  X-Content-Type-Options: nosniff 
  Server: WWW Server/1.1 X-XSS-Protection: 1; mode=block 
  Set-Cookie: __AntiXsrfToken=6142de1c5d474da780530da39fea033f; path=/;HttpOnly; Secure
  Date: Thu, 12 Jan 2017 15:56:47 GMT
  </code></pre>
  
  <p>By the way, in Internet Explorer (IE) 11.0.9600.18537 objects like images are not loaded (as I believe Powershell works "under the hood" using IE DLLs) and the "hourglass" is running permanently too next to the tab of the requested URI.</p>
  
  <p>So again my question: Has this issue to do with this <a href="https://connect.microsoft.com/PowerShell/feedbackdetail/view/1557783/invoke-webrequest-hangs-in-some-cases-unless-usebasicparsing-is-used" rel="nofollow noreferrer">bug</a> in Powershell or could it be something else?</p>