1

We are implementing the Orange business apps API. For this, we need to call an Orange service. This service has Bearer type authentication (Oauth2). I am able to get access token successfully and access token validity is 90 days. By using latest access token, I tried to call an Orange service by sending the access token in header but getting unauthorized access error every time.

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;
    }

Can any one help me in this?

Thank you for your help!

4

1 回答 1

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不能在一个引号内工作',所以它会“按原样”发送

于 2018-09-24T07:48:23.613 回答