2

New to powershell 4.0 and trying to figure out web-requests.

Simply trying to logon to facebook with the below code:

$azr = Invoke-WebRequest -uri "https://www.facebook.com/" -SessionVariable sbv

$azr|gm 
$azr.Forms
$db_Form = $azr.Forms[0]
$db_Form 
$db_Form.Fields 
$db_Form.Fields["email"]="LoginEmail@gmail.com"
$db_Form.Fields["pass"]="Username"

$db_Form.Action 

$r = Invoke-WebRequest -Uri ("https://www.facebook.com/"+$db_Form.Action) -WebSession $sbv -Method Post -Body $db_Form.Fields

But I keep getting an error, telling me

Invoke-WebRequest : The request was aborted: The connection was closed unexpectedly.

And directs the error to the last line of code. Any clues as to why this is?

LeChuck
  • 71
  • 9
  • I think your script is not complete. You must create a header in your message (place a user agent) allow cookies at the time of request. You have an example in C# but I never tried with PowerShell. http://stackoverflow.com/questions/8425593/c-sharp-httpwebrequest-post-login-to-facebook – Jean-Claude Colette Sep 29 '16 at 12:25

0 Answers0