Issue
I am trying to use curl command with following line below and encountering errors.
curl -H "Content-Type: application/json" -X POST -d '{"name": "ggg","address":"gemany" }' urlplaceholder
Invoke-WebRequest : Cannot bind parameter 'Headers'. Cannot convert the "Content-Type: application/json" value of type "System.String" to type "System.Collections.IDictionary".
At line:1 char:9
+ curl -H "Content-Type: application/json" -X POST -d '{"name": "ggg"," ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Solution
I can say you are using Microsoft Power shell utility.. which has different syntax. It is expecting a hash table type value for headers
@{<name> = <value>; [name = <value> ] ...}
If you really want it to be working in power shell, please go through power shell's Invoke-WebRequest syntax
When I ran this command in curl, it worked, no issues.
A tweak is if you have git installed in windows, you can set the command prompt to Git\mingw64\bin, and from there execute your curl commands
Answered By - Rajani B Answer Checked By - Clifford M. (WPSolving Volunteer)