[英]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: 您的代码中存在几个问题:
curl_setopt($ch, CURLOPT_URL, POSTURL);
curl_setopt($ch, CURLOPT_URL, POSTURL);
you should change $ch
variable to $c
$ch
变量更改为$c
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
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.