Search code examples
powershellrest

Invoke-WebRequest, POST with parameters


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?


Solution

  • 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