Reputation: 601
I am trying to form the following CURL post request through PHP? How do i do it, all of what i tried came back as invalid post parameters.
This is what i am trying to POST through php (i have the API_KEY, api_sig.. but dont know how put below post query through in PHP):
curl -d "api_key=KEY&sig=SIGNATURE&time_stamp=20&json=1" \ http://api.i.com/v1/update/
Upvotes: 1
Views: 2848
Reputation: 1
Please refer to following PHP code
define('POSTURL', 'http://api.iq.com/v1/update/');
define('POSTVARS', 'api_key=API_KEY&api_sig=SIGNATURE&time_stamp=20090612111832&json=1'); //removed typo
$ch = curl_init(POSTURL);
curl_setopt($ch, CURLOPT_POST ,1);
curl_setopt($ch, CURLOPT_POSTFIELDS ,POSTVARS);
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1); // RETURN THE CONTENTS OF THE CALL`
$Rec_Data = curl_exec($ch);`
curl_close($ch);
Upvotes: 0
Reputation: 1458
Put everything in one line:
curl -d "api_key=API_KEY&api_sig=SIGNATURE&time_stamp=20090612111832&json=1" http://api.iq.com/v1/update/
Use exec()
to run it, for example
exec("curl -d \"api_key=API_KEY&api_sig=SIGNATURE&time_stamp=20090612111832&json=1\" http://api.iq.com/v1/update/", $results);
$results
holds the returned data.
Upvotes: 0
Reputation: 472
This should work
$url = "http://api.iq.com/v1/update/";
$data = "api_key=API_KEY&api_sig=SIGNATURE&time_stamp=20090612111832&json=1";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST ,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); /* obey redirects */
curl_setopt($ch, CURLOPT_HEADER, 0); /* No HTTP headers */
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); /* return the data */
$result = curl_exec($ch);
curl_close($ch);
Upvotes: 5