我正在尝试连接云台管理器 Restful API。我的组织有一个帐户和一个 API KEY。我的 cURL 请求不断失败,来自 API 端点的 401 未授权响应。这是我在 PHP 中的 cURL 请求:
// from Gimbal Manager:
define('ORG_API_KEY', 'XXXXXXXXXXXXXXXXX') ;
// new beacon registration object:
$post = array (
"factory_id" => "XXXX-XXXXX",
"name" => "NewBeacon",
"latitude" => 12345
"longitude" => 67890,
"visibility" => "public"
);
$url = "https://manager.gimbal.com/api/beacons";
$headers = array(
'AUTHORIZATION: Token token=' . ORG_API_KEY,
'Content-type: application/json'
) ;
$debug = 1 ;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers, TRUE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
if ($debug) {
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
}
curl_setopt($crl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($crl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result = curl_exec($ch);
(编辑)和这里的请求标头(来自上面的 $headerSent var)
POST /api/beacons HTTP/1.1
Host: manager.gimbal.com
Accept: */*
Content-Length: 577
Expect: 100-continue
Content-Type: multipart/form-data; boundary=----------------------------ce1a4e9dd55e
这是 Gimbal 的回复:
HTTP/1.1 401 Unauthorized
Cache-Control: no-cache
Content-Type: text/html; charset=utf-8
Date: Sat, 29 Aug 2015 20:05:10 GMT
Server: Apache
Status: 401 Unauthorized
Vary: Accept-Encoding
WWW-Authenticate: Token realm="Application"
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Request-Id: 7abe53cd-d161-4886-bb61-8cfedf71743a
X-XSS-Protection: 1; mode=block
Content-Length: 27
Connection: keep-alive
HTTP Token: Access denied.
我尝试了几种不同的方式来表达 AUTH 令牌:
AUTHORIZATION: <$token>
AUTHORIZATION: Token <$token>
AUTHORIZATION: Token token=<$token>
他们都给出相同的 401 响应。我注意到这里和其他地方的其他票证描述了类似的问题,但没有一个被标记为已解决。
有没有人幸运地连接到 Gimbal Manager API?如果是这样,您的代码看起来不同吗?