开发者

Sorenson 360 API call with cURL+PHP returning false

开发者 https://www.devze.com 2023-02-17 23:55 出处:网络
I\'m trying to access the Sorenson-360 API with cURL and PHP, however I am not able to authenticate with their API.

I'm trying to access the Sorenson-360 API with cURL and PHP, however I am not able to authenticate with their API.

The code I'm using is:

$postURL = "https://360services.sorensonmedia.com/sessions";
$postVars = "username=".$username."&password=".$password;
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $postURL);
var_dump($c);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_HEADER, 0);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, $postVars);
$content = curl_exec($c);
var_dump($content);
//echo $content;
curl_close($c);

My response printed out on the page is:

resource(4) of type (curl) string(1) " "

The API documention I am trying to use is here: http://developers.sorensonmedia.com/api/accounts/login

A similar post on StackOverflow that yeilded no solution other than to use zend (which I don't have nor understand) was posted here: PHP: posting data 开发者_StackOverflowto REST API (Sorenson 360)

I don't have access to install anything on my server and the Zend getting started documentation is not clicking with me. I would prefer to use cURL for this as I'm somewhat familiar with it.


There're several problems in your code:

  1. in curl_setopt($ch, CURLOPT_URL, POSTURL); you should change $ch variable to $c
  2. security certificate of the site you're connecting to is not trusted. To disable this check you need to add curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
  3. finally, why do you need to define constants for url and post parameters? What's wrong with good old PHP variables?

Upd:

For debugging purposes, I suggest that you turn on the CURLOPT_HEADER option:

curl_setopt($c, CURLOPT_HEADER, true);

If you get HTTP/1.1 500 Internal Server Error for response, something is wrong with the service you're calling, not with your code.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号