【发布时间】:2016-11-22 00:16:40
【问题描述】:
这是我的代码
$data = array(
'grant_type' => 'Password',
'username' => 'username',
'password' => 'pwd',
'DeviceId' => ''
);
$url = "http://test/sync/oauth/token";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 201 ) {
die("Error: call to URL $url failed with status $status, response $response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
}
curl_close($curl);
print_r($response);`
我认为是正确的,但是服务器返回这个错误
错误:调用 URL http://test/sync/oauth/token 失败并显示状态 400, 响应 {"error":"unsupported_grant_type"}, curl_error , curl_errno 0
哪里出错了?
【问题讨论】:
-
cURL 工作正常 - 错误似乎是由
http://test/sync/oauth/token生成的 JSON ...我将冒险猜测并说它期望grant_type是 password(带有小写的“p”)但没有看到该脚本的来源,仅此而已,猜测。 -
是的,您是对的,但错误仍然存在:错误:调用 URL test.audipsp.volkswagengroup.it/sync/oauth/token 失败,状态为 400,响应 HTTP/1.1 100 继续 是的,您是对的,但错误仍然存在:HTTP/1.1 400 Bad Request Cache-Control: no-cache Pragma: no-cache Content-Length: 34 Content-Type: application/json;charset=UTF-8 Expires: -1 Server: Microsoft-IIS/8.5 X-Powered-By: ASP.NET 日期:2016 年 7 月 19 日星期二 10:29:27 GMT {"error":"unsupported_grant_type"}, curl_error , curl_errno 0