Nathan Riley
asked on
Curl & PHP Command Help
When I run this from SSH:
curl -i -d account_id=11494158 -d authhash=5638679d0d26bc340 4d9f99eabf 70efc http://manage.ivr-platform.com:8083/11494158/
It returns data without any issues. Yet when I try it in my PHP curl command it returns nothing even when dumping the variable. Any ideas?
$url = "http://manage.ivr-platform.com:8083/".$account."/";
$params = array(
'account_id' => $account,
'authhash' => md5($email.$pass)
);
//echo $url;
//die();
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curl);
curl_close($curl);
var_dump($result);
curl -i -d account_id=11494158 -d authhash=5638679d0d26bc340
It returns data without any issues. Yet when I try it in my PHP curl command it returns nothing even when dumping the variable. Any ideas?
$url = "http://manage.ivr-platform.com:8083/".$account."/";
$params = array(
'account_id' => $account,
'authhash' => md5($email.$pass)
);
//echo $url;
//die();
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curl);
curl_close($curl);
var_dump($result);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think the POST_FIELDS needs to be a standard query string, not an array. When PHP tries to "stringify" an array, the output is the word "Array." This has been a "feature" of PHP since the beginning. It should really be a Warning, but this was a decision taken many years ago, and it's too late to fix it now.
According to the PHP manual
I am guessing that the receiving service does not like the data encoded as multipart/form-data which is why the array does not work.
Passing an array to CURLOPT_POSTFIELDS will encode the data as multipart/form-data, while passing a URL-encoded string will encode the data as application/x-www-form-urlencoded.
I am guessing that the receiving service does not like the data encoded as multipart/form-data which is why the array does not work.
ASKER