PowerShell v3 Invoke-WebRequest: Troubles with forms PowerShell v3 Invoke-WebRequest: Troubles with forms powershell powershell

PowerShell v3 Invoke-WebRequest: Troubles with forms


Try doing the post directly e.g.:

$formFields = @{username='john doe';password='123'}Invoke-WebRequest -Uri $myUrl -Method Post -Body $formFields -ContentType "application/x-www-form-urlencoded"


To address your problem with the unsigned/untrusted certificate, add the line

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}

before the Invoke-WebRequest statement


The example in the question works, but you have to use rb and not $rb in the first line:

$response = Invoke-WebRequest -Uri $myUrl -Method Default -SessionVariable rb

I also had to use ($myUrl + '/login') since this is my login address.

$response = Invoke-WebRequest -Uri ($myUrl + '/login') -Method Default -SessionVariable rb

And in the last line used ($myUrl + $form.Action):

$response = Invoke-WebRequest -Uri ($myUrl + $form.Action) -WebSession $rb -Method POST