Since I upgraded to Windows 8 a lot of my PowerShell scripts relying on launching an invisible IE won’t quite work anymore, so I tried switching to the Invoke-WebRequest
If you're me and have been troubleshooting a bad Web Request, in my case a -Body
that was becoming null
at my API, then you will want to know about the gotcha that is about interleaving your line continuations with comments. This
$r = iwr -uri $url `
-method 'POST' `
-headers $headers `
# -contenttype 'application/x-www-form-urlencoded' ` # default
-Body $body
Notice the commented out line # -contenttype 'application/x-www-form-urlencoded' # default
Putting a comment truncates the remaining back-ticked line continuation. Therefore, in my case my web request ended up with a request having 0-byte payload.