简体   繁体   English

带有cURL + PHP的Sorenson 360 API调用返回false

[英]Sorenson 360 API call with cURL+PHP returning false

I'm trying to access the Sorenson-360 API with cURL and PHP, however I am not able to authenticate with their API. 我正在尝试使用cURL和PHP访问Sorenson-360 API,但是我无法通过其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) " " (curl)类型string(1)的resource(4)“”

The API documention I am trying to use is here: http://developers.sorensonmedia.com/api/accounts/login 我要使用的API文档在这里: 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 to REST API (Sorenson 360) 在StackOverflow上类似的帖子也发布了,除了使用zend(我没有理解)以外,没有其他解决方案: PHP:将数据发布到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. 我无权在服务器上安装任何东西,并且Zend入门文档没有与我一起单击。 I would prefer to use cURL for this as I'm somewhat familiar with it. 我宁愿对此使用cURL,因为我对此有些熟悉。

There're several problems in your code: 您的代码中存在几个问题:

  1. in curl_setopt($ch, CURLOPT_URL, POSTURL); curl_setopt($ch, CURLOPT_URL, POSTURL); you should change $ch variable to $c 您应该将$ch变量更改为$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); 要禁用此检查,您需要添加curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
  3. finally, why do you need to define constants for url and post parameters? 最后,为什么需要为url和post参数定义常量? What's wrong with good old PHP variables? 好的旧PHP变量怎么了?

Upd: 更新:

For debugging purposes, I suggest that you turn on the CURLOPT_HEADER option: 为了进行调试,建议您打开CURLOPT_HEADER选项:

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. 如果您收到HTTP/1.1 500 Internal Server Error响应,则表示您正在调用的服务有问题,而不是代码有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM