1

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
1
  • Use "curl.exe -H...." instead. Commented Jul 27, 2024 at 14:48

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

Using powershell 7 seemed to clear this issue up.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.