2

This works fine directly in bash:

curl https://test.url.com/api/id/98765 -H 'API_KEY: xxxxxxxxxx' -H 'Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=='

This does not work in PHP (nothing is returned):

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,'https://test.url.com/api/id/98765');
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER,  array(
                                            "API_KEY: xxxxxxxxxx8",
                                            "Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=="
                                            ));         
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
$results = curl_exec($curl);
echo 'out: '.$results;

No errors are returned. I'm expecting results in json

8
  • @user2029890 Is your error reporting is ON? Commented Jan 22, 2014 at 18:51
  • yes, error reporting is on. I tested by deliberately creating a syntax error Commented Jan 22, 2014 at 18:52
  • Blat! Nevermind, now I see that you have it working in CURL. *Goes and digs deeper* Commented Jan 22, 2014 at 18:53
  • Can you try adding curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);? Commented Jan 22, 2014 at 18:56
  • Is the request getting sent at all? If yes, what exactly is getting sent? Commented Jan 22, 2014 at 18:57

2 Answers 2

2

Hazarding a guess (and we ultimately determined this to be true) that you need:

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);

(note that 0 is synonymous with false).

This stops the client from verifying the SSL certificate of the remote location. I suggested this because your url is on https:// but it looks like a custom built solution which you likely don't have a public trusted cert configured for it (yet).

More information on CURLOPT_SSL_VERIFYPEER is available in the php docs.

Sign up to request clarification or add additional context in comments.

Comments

0

The following PHP code is working for me fine to a renowned API. Here i have to implement CURLOPT_SSL_VERIFYPEER and CURLOPT_USERAGENT. you can try with this

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://testurl.com/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);

$result = curl_exec($ch);
curl_close($ch);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.