Search code examples
powershellauthenticationwebrequest

Invoke-WebRequest login to web site


What I am attempting is to use Powershells Invoke-WebRequest Cmdlet to login to a web site. Here's my code:

$login = Invoke-WebRequest -Uri https://www.franklinamerican.com/ext/general?npage=home -SessionVariable franklin

$form = $login.Forms[0]

$form.Fields["userName"] = "username123"
$form.Fields["brokerPassword"] = "password456"

$login = Invoke-WebRequest -Uri https://www.franklinamerican.com/ext/general?npage=home -WebSession $franklin -Method POST -Body $form.Fields

$login.StatusDescription

I receive an 'OK' from the StatusDescription regardless of whether the credentials are correct, which seems odd and confusing. What am I missing here? Any help would be much appreciated. Thanks everyone

edit: Results of calling $login.InputFields

[1]: image of https://i.sstatic.net/n52XO.png


Solution

  • What you're missing from interpreting the results is that $login.StatusDescription refers to the HTTP Status which in this case is likely HTTP status code 200, which translates to "OK".

    That is unrelated to the web site's (forms-based) authentication. You're missing something that is needed by the form. Look at $login.Content and see if the web site gave you a more specific error in the HTML that you can use.