【发布时间】:2018-02-12 12:38:49
【问题描述】:
我正在使用下面的代码使用 curl 发布到 API,但是遇到了问题/错误
“HTTP/1.1 400 错误请求内容类型:application/json 日期:星期一,2017 年 9 月 4 日 05:40:40 GMT 服务器:Apigee 路由器内容长度:231 连接:keep-alive {"developerMessage ":"请求中不存在所需的参数 client_id,client_secret,grant_type","userMessage":"","errorCode":"AUTH-008","more info":""} "
它说有些参数不存在,而我已经提供了下面代码中所需的所有参数
$url ="mysite.com/authentication/v1/gettoken?client_id=T9hq3zS1CedgVb1mAYECM&client_secret=03hRRTz&grant_type=authorization_code&code=vWnbF8G3UhvMe66-R37lM117LcxjeBLsFwEeLBAy&redirect_uri=mysite.com/testing.php";
$header = array("content-type: application/x-www-form-urlencoded");
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_ENCODING, "");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)');
echo $retValue = curl_exec($ch);
echo '<br><br>';
//$response = json_decode(curl_exec($ch));
//$ee = curl_getinfo($ch);
//print_r($ee);
print_r($retValue);
【问题讨论】:
-
根据 API 消息,您缺少一些凭据。 API 应该在哪里读取凭证?您是否尝试在请求标头中发送这些内容?