Sending POST Data via PowerShell

Often, feedback or votes on Web pages are sent back via POST requests. You can send this kind of information via PowerShell as well. You should simply create a POST request with the target URL and the desired parameters/information and send it off:

$url = "http://someurl"
$parameters = "vote=true&poll_id=2" # your POST parameters

$http_request = New-Object -ComObject Msxml2.XMLHTTP
$http_request.open('POST', $url, $false)
$http_request.setRequestHeader("Content-type",
"application/x-www-form-urlencoded")
$http_request.setRequestHeader("Content-length", $parameters.length)
$http_request.setRequestHeader("Connection", "close")
$http_request.send($parameters)
$http_request.statusText

Twitter This Tip! ReTweet this Tip!


Posted Apr 29 2010, 08:00 AM by ps1

Comments

ober08 wrote re: Sending POST Data via PowerShell
on 04-29-2010 6:25 PM

this tip is nice but doesn't give the right data back if the parameter is off.  currently it is $parameters = "vote=true&poll_id=2".  if you change it to $parameters = "vote=true&poll_id=1" and 1 doesn't exist, the post will still say OK instead of NOT FOUND

Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.