2

Many days ago, I read an interesting question about sending JSON data to webserver, at here: Send JSON by cURL always returns "No access".

And, bellow is full code for answer:

<?php

//API URL
$url = 'http://www.example.com/test.php';
$data = "?code=69Uy8&token=952b0f024c1e66a2a0f6f7759c2cdbfb";

//Initiate cURL.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url . $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

//Execute the request
$result = curl_exec($ch);

?>

Now, I want to send multiple data values to http://www.example.com/test.php:

code=69Uy8&token=952b0f024c1e66a2a0f6f7759c2cdbfb
code=asf5C&token=1af76d050b0831537a5f8a4153290a6f
code=U3dhB&token=b2e909fcefaeef184c01f0ac6f284db8
code=I4pe5&token=34de7a8929842f80a44abd4af4a1f0b1
code=KaoBn&token=f0e953832394a69c6ebe2d518898584a
code=bgpTb&token=82b1eb052bb4b9473a695bc42942fe88
code=gBPuf&token=9e9ffe7707cc155aba665c2ac65bba62
code=e3uAx&token=edb90988db61e78b9167116e376e9a2c
code=fje60&token=a435c033a71b2244629de402c0a650a1
code=BTdhG&token=dff6f60bf424ce67d51f7d7270a8c1d0

How to send multiple data value to server, with JSON, by PHP?

Community
  • 1
  • 1
g8312437
  • 49
  • 8

1 Answers1

0

CURL support sending data arrays, You can make your data array and send it to server with CURL see this link Already asked in stack overflow

You can send an JSON array, that will required to be decoded when server receives it, but with CURL you can send array, just use is_array() function to check whether requested parameters are array or single variable.

Community
  • 1
  • 1
Marmik Bhatt
  • 607
  • 4
  • 16
  • Provide more code to understand problem – Marmik Bhatt Aug 07 '15 at 03:11
  • Ok, now I think, does your server (test.php file) can process array in GET Request, I mean have you used, is_array() function to check whether uploaded data is single variable or an array() ? Also show test.php code – Marmik Bhatt Aug 07 '15 at 03:17