Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use curl multipart form data to post array field from command line ?

Tags:

terminal

curl

Using curl request

curl -v -X PATCH -H "Content-Type:multipart/form-data" -H "Accept:application/json" -H "Auth-token:abcde" -F "first_name=snme" -F 'tags[]=chec' -F 'tags[]=chec2' http://example.com/api/users/1

I want to post tags as an array. So parsing the request i should get tags = ['check' , 'check2'] etc.

What I get now is {"tags[]" = "chec"}

like image 500
Dharmanshu Kamra Avatar asked Jan 14 '14 21:01

Dharmanshu Kamra


2 Answers

Try this:

   curl -X POST -d 'tags[]=check&tags[]=check2' 'http://example.com/api/users/1' -v

For multipart it should work with what you have tried:

   curl -X POST -F 'tags[]=check1' -F 'tags[]=check2' 'http://example.com/api/users/1' -v

Returns:

    {"tags":["chec","chec2"], ... }
like image 91
Swathi K Avatar answered Oct 04 '22 14:10

Swathi K


For some server, you can use

curl -X POST -F 'tags=check1' -F 'tags=check2' 'http://example.com/api/users/1' -v

like image 21
chris Avatar answered Oct 04 '22 14:10

chris