我们正在实现Orange商业应用API。为此,我们需要调用Orange服务。此服务具有承载类型身份验证(Oauth2)。我能够成功获取访问令牌,并且访问令牌的有效期为90天。通过使用最新的访问令牌,我尝试通过在标头中发送访问令牌来调用Orange服务,但每次都会出现未经授权的访问错误。
Here is code
public static function sendEventProductOrder($eventProductOrdering) {
$jsonMapper = new JsonMapper();
$opts = array('http' => array('method'=>'POST',
'header'=>'Content-type: application/x-www-form-urlencoded\r\n'.'Authorization: Bearer xxxxxxxxxxxxxxxxx\r\n',
'content' => json_encode($jsonMapper->unmap($eventProductOrdering)),
));
$context = stream_context_create($opts);
if (($stream = fopen("https://api.orange.com/mba/productordering/v2/event", 'r', false, $context)) !== false) {
$content = stream_get_contents($stream);
$header = stream_get_meta_data($stream);
fclose($stream);
return HelperMisc::isEqualIgnoreCase($header['wrapper_data']['0'], 'HTTP/1.1 201 Created');
}
return false;
}
有人可以帮我吗?
谢谢您的帮助!
答案 0 :(得分:1)
您可以尝试将报价'
更改为"
吗?像这样:
$requestArray = [
'name' => 'User',
'age' => 100
];
'header' => "Content-type: application/x-www-form-urlencoded\r\n" .
"Authorization: Bearer xxxxxxxxxxxxxxxxx\r\n",
'content' => http_build_query($requestArray)
由于\r\n
在一个引号'
中不起作用,因此它按原样发送”