【发布时间】:2017-12-31 17:32:27
【问题描述】:
我在获取访问令牌时遇到了一些问题:
api.hybrid.ru/token
这个 API 的文档是俄语 (Link) ,它基本上说:
Headers
POST /token HTTP/1.1
Host: api.hybrid.ru
Content-Type: application/x-www-form-urlencoded
Data:
grant_type=client_credentials&client_id={client_id}&client_secret={client_secret}
我有有效的 client_id 和 client_secret(hybrid.ru 技术人员给了我这些),它甚至不会返回错误消息。 我使用 CURL,我的代码如下:
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
$ch = curl_init();
$url = "https://www.api.hybrid.ru/token";
$post_data = array(
'grant_type'=> 'client_credentials',
'client_id'=>'********',
'client_secret'=>'********'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"POST /token HTTP/1.1",
'Content-Type: application/x-www-form-urlencoded',
"host: api.hybrid.ru"
));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch,CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_POSTREDIR, 3);
$output = curl_exec($ch);
curl_close($ch);
print_r($output);
?>
我想,如果 client_id 或 client_secret API 有错误,至少应该返回一些错误消息。
还有一个问题,client_secret 可以包含字符“=”吗?他们给了我带有尾随“=”符号的client_secret。无论如何,无论有没有字符,它都不会返回任何数据。
有什么帮助吗?
更新 1
在遵循 Lorna Mitchell 的回答后,我收到以下消息:
Array (
[url] => https://api.hybrid.ru/Views/Errors/DefaultError.cshtml?aspxerrorpath=/
[content_type] => text/html; charset=utf-8 [http_code] => 500 [header_size] => 483
[request_size] => 440
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 1
[total_time] => 3.853833
[namelookup_time] => 0.972059
[connect_time] => 1.178887
[pretransfer_time] => 1.406303
[size_upload] => 479
[size_download] => 1763
[speed_download] => 457
[speed_upload] => 124
[download_content_length] => 1763
[upload_content_length] => 479
[starttransfer_time] => 1.612792 [redirect_time] => 2.028607
[redirect_url] =>
[primary_ip] => 212.8.236.42
[certinfo] => Array ( )
[primary_port] => 443
[local_ip] => 162.214.7.244
[local_port] => 46088
)
HTTP/1.1 100 Continue HTTP/1.1
302 Found
Date: Wed, 26 Jul 2017 16:47:47 GMT
Content-Length: 166
Connection: keep-alive
Location: /Views/Errors/DefaultError.cshtml?aspxerrorpath=/
Server: Hybrid Web Server HTTP/1.1 100 Continue HTTP/1.1 500 Internal Server
Error
Date: Wed, 26 Jul 2017 16:47:49 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 1763
Connection: keep-alive
Cache-Control: private
X-AspNet-Version: 4.0.30319
Server: Hybrid Web Server
之后有什么想法吗?
【问题讨论】:
-
您是否尝试过使用 telnet 发送帖子数据并查看是否收到任何响应?
-
这是第一次听说 telnet,我遵循了 Lorna 的回答,我可能会通过电子邮件发送有关此 Hybrid 的信息,如果他们说问题在我这边,我会尝试您的方式,但不知道如何使用 telnet可以给我任何不同的答案,如果你能解释一下,那就太好了。谢谢你的回答。