我怎样才能从拉拉维尔5.3的咕噜声中得到回应

我试试像这样:


$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();

执行时,结果是错误curl_setopt_array():不能将输出类型的流表示为 STDIO FILE* 如何获取响应?


我在邮递员中尝试,它的成功得到回应


但是我尝试使用咕噜声,它失败了


慕哥6287543
浏览 54回答 2
2回答

慕村9548890

您可以尝试以下代码: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 ( \GuzzleHttp\Exception\ClientException $exception ) {    echo $exception->getResponse()->getBody();}

猛跑小猪

我这样解决了 $requestContent = [            'headers' => [                'Accept' => 'application/json',                'Content-Type' => 'application/json',                'Authorization'=>'Bearer '.$token,            ],            'json' => [                'outboundSMSMessageRequest'=>[                                        'address'=> "tel:youre-phone",                'senderAddress'=>'tel:+phone_rec',                    'outboundSMSTextMessage'=>[                        'message'=> 'Hello test !'                    ]                ]            ]        ];        try {            $client = new Client();            $res = $client->request('POST', 'https://api.orange.com/smsmessaging/v1/outbound/tel:+phone_rec/requests/', $requestContent);            $response = json_decode($res->getBody());            dd($response);        } catch (RequestException $re) {        }
打开App,查看更多内容
随时随地看视频慕课网APP