Reputation: 37
I searched the whole web but I guess I overlook something simple.
I want to send a FORM with the Keys "Foo" and the Value "Bar" as POST to URL "api.foobar.com".
In Python I could have done it in 2 Minutes but I am new to PowerShell and want to learn it. So maybe someone can help me.
edit:
I tried the following:
$Body = @{
Foo = 'Bar'
}
Invoke-WebRequest 'http://api.foobar.com' -Body $Body -Method
'POST'
and the API answers "Value Foo is missing". The API expects "Foo" als key and "Bar" is the value. The response of the API is JSON.
Upvotes: 0
Views: 1365
Reputation: 129
If the query should or can be JSON try something like:
$JSONQuery = '
{
"Foo":"Bar"
}'
Invoke-WebRequest 'http://api.foobar.com' -Body $JSONQuery -Method 'POST' -ContentType "application/json"
Upvotes: 1