Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cURL post with JSON parameters? [duplicate]

Tags:

json

post

curl

I'm not sure if this is possible, but i am trying to curl a post, but with a json as the parameters, like such:

curl -X POST 'https://myserver/action?params={"field1":"something","whatever":10,"description":"body","id":"random","__oh__":{"session":"12345678jhgfdrtyui"}}'

however, i keep getting some error curl: (3) [globbing] nested braces not supported at pos X

how do i do this?

like image 577
David T. Avatar asked Aug 21 '14 20:08

David T.


People also ask

How do I POST JSON data with curl?

To post JSON data using Curl, you need to set the Content-Type of your request to application/json and pass the JSON data with the -d command line parameter. The JSON content type is set using the -H "Content-Type: application/json" command line parameter. JSON data is passed as a string.

How do I curl POST request?

Users can send data with the POST request using the -d flag. The following POST request sends a user and a pass field along with their corresponding values. POSTing with curl's -d option will include a default header that looks like: Content-Type: application/x-www-form-urlencoded .


1 Answers

The curl error is due to braces {} and square brackets [] being special curl globbing characters. Use the -g option to turn off globbing and you should be fine.

Same issue as this post: How to PUT a json object with an array using curl

like image 118
Yonik Avatar answered Oct 11 '22 16:10

Yonik