-1

Hi I have api with the following requirement.

Send post data like that:

data[email]  : test@test.com
data[firstName] :first
data[lastName]  : last
data[country]   :DE

How can I send it via curl?

Dovydas Šopa
  • 2,282
  • 8
  • 26
  • 34
Scopi
  • 663
  • 1
  • 6
  • 21
  • Possible duplicate of [How do I use arrays in cURL POST requests](http://stackoverflow.com/questions/13596799/how-do-i-use-arrays-in-curl-post-requests) – jmattheis Jan 31 '17 at 07:55

1 Answers1

-1

See this answer: How do I use arrays in cURL POST requests

if you already have the array $data:

$field_string = http_build_query($data);

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
...
Community
  • 1
  • 1
sadlyblue
  • 2,992
  • 7
  • 22
  • 19