Senin, 14 Februari 2011

Powershell - Automate HTTP POST Process

I was trying to figure out a way to automate testing a form with HTTP POST. I found this link:

http://powershell.com/cs/blogs/tips/archive/2010/04/29/sending-post-data-via-powershell.aspx
It gave me the base and with just a few quick tweaks I got it running with the following script:
function spam{
$url = "http://www.theboard.com/post_item.aspx"
$parameters = "name=test=&subject=test&body=test body."

$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
}
To validate some load stress, I just automated the posting.
for($i = 0; $i -lt 100; $i++)
{
spam
Write-Host $i
}
I had gotten the parameters I needed to work with, $url and $parameters, by using LiveHttpHeaders with Firefox. All you have to do is save the output of your post and cut and paste.

0 komentar:

Posting Komentar

 
Powered by Blogger