Guzzle6错误无效的资源类型:发送GuzzleHttp \ Psr7 \ Request时的数组 [英] Guzzle6 error Invalid resource type: array when send a GuzzleHttp\Psr7\Request

查看:659
本文介绍了Guzzle6错误无效的资源类型:发送GuzzleHttp \ Psr7 \ Request时的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用GuzzleHttp \ Psr7 \ Request发送代码,但是我却收到错误消息无效的资源类型:数组,以下是我的代码

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

我正在关注指南.

推荐答案

如果要在请求中使用JSON,只需使用json_encode()创建它:

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

这篇关于Guzzle6错误无效的资源类型:发送GuzzleHttp \ Psr7 \ Request时的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆