Link to home
Start Free TrialLog in
Avatar of Nathan Riley
Nathan RileyFlag for United States of America

asked on

Curl & PHP Command Help

When I run this from SSH:

curl -i -d account_id=11494158 -d authhash=5638679d0d26bc3404d9f99eabf70efc 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);
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Nathan Riley

ASKER

Thank you that works, trying to figure out why my curl call didn't work though.
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

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.