I try like this :
$client = new Client(); $res = $client->request('POST', 'https://api.orange.com/smsmessaging/v1/outbound/tel:+phone/requests/', [ 'headers' => [ 'Accept' => 'application/json', 'Content-Type' => 'application/json', 'Authorization'=>'Bearer '.$token, /*'Content-Type' => 'application/x-www-form-urlencoded',*/ ], /*'form_params' => $body ,*/ 'json' => [ 'outboundSMSMessageRequest'=>[ 'address'=> 'tel:+$phone', 'senderAddress'=>'tel:+phone_rec', 'outboundSMSTextMessage'=>[ 'message'=> 'Hello test!' ] ]], 'debug' => true, 'verify' => false, ] ); $res->getStatusCode(); // 200 $res->getHeader('content-type'); // 'application/json; charset=utf8' $res->getBody();
When executed, the result is an errror curl_setopt_array(): cannot represent a stream of type Output as a STDIO FILE* How can I get the response?
I try in postman, it success get response
But I try use guzzle, it failed
Advertisement
Answer
You can try code below:
try { $client = new Client(); $token = 'token'; $res = $client->request('POST', 'https://api.orange.com/smsmessaging/v1/outbound/tel:+phone/requests/', [ 'headers' => [ 'Content-Type' => 'application/json', 'Authorization'=>'Bearer '. $token, ], 'json' => [ 'outboundSMSMessageRequest'=>[ 'address'=> "tel:youre-phone", 'senderAddress'=>'tel:+phone_rec', 'outboundSMSTextMessage'=>[ 'message'=> 'Hello test!' ] ]], 'debug' => true, 'verify' => false, ] ); echo $res->getBody(); } catch ( GuzzleHttpExceptionClientException $exception ) { echo $exception->getResponse()->getBody(); }