Guzzle6 error Invalid resource type: array when send a GuzzleHttp\Psr7\Request

六眼飞鱼酱① 提交于 2019-12-02 04:05:01

问题


I am trying to send a code by using GuzzleHttp\Psr7\Request,somehow I get error Invalid resource type: array, the following is my codes

$params = ["name"=>"myName","id"=>"myId"];
$client = new Client();
$request = new Request('PUT','https://api.hitbox.tv/media/live/myName?authToken=myToken',["content-type"=>'application/json'],["json"=>$params]);

$response = $client->send($request);

I'm following this guide.


回答1:


If you want to use JSON in the request, just create it with json_encode():

$request = new Request(
    'PUT',
    'https://api.hitbox.tv/media/live/myName?authToken=myToken',
    ["content-type" => 'application/json'],
    json_encode($params)
);


来源:https://stackoverflow.com/questions/38633068/guzzle6-error-invalid-resource-type-array-when-send-a-guzzlehttp-psr7-request

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!