Invoke-WebRequest, POST with parameters

kylex picture kylex · Jun 26, 2013 · Viewed 254.8k times · Source

I'm attempting to POST to a uri, and send the parameter username=me

Invoke-WebRequest -Uri http://example.com/foobar -Method POST

How do I pass the parameters using the method POST?

Answer

Jellezilla picture Jellezilla · Jun 26, 2013

Put your parameters in a hash table and pass them like this:

$postParams = @{username='me';moredata='qwerty'}
Invoke-WebRequest -Uri http://example.com/foobar -Method POST -Body $postParams