Php 使用HTTP使用API终结点时出错

Php 使用HTTP使用API终结点时出错,php,laravel,laravel-5,guzzle,Php,Laravel,Laravel 5,Guzzle,我使用Guzzle使用API,但由于某些原因,我出现以下错误: http_生成_查询:参数1应为数组或对象。给出的值不正确 我不知道我可能做错了什么。这是我的代码: $data = ["name" => "joe doe"]; $jsData = json_encode($data); $headers = [ 'content-type' => 'application/json', 'Authorization' => "Bearer {$token}"

我使用Guzzle使用API,但由于某些原因,我出现以下错误:

http_生成_查询:参数1应为数组或对象。给出的值不正确

我不知道我可能做错了什么。这是我的代码:

$data = ["name" => "joe doe"];
$jsData = json_encode($data);

$headers =  [
    'content-type' => 'application/json',
    'Authorization' => "Bearer {$token}"
];

$call = $this->client->post(env('URL'),[
    "headers" => $headers,
    'form_params' => $jsData
]);

$response = json_decode($call->getBody()->getContents(), true);
编辑


客户端错误:POSThttp://localhost/send 导致400个错误的请求响应:{错误:{代码:400,消息:未能解码JSON对象:无法解码JSON对象,u被截断…

您看到错误的原因是应该是一个数组,但您正在通过返回字符串的JSON_encode运行数组:

$data = ["name" => "joe doe"];
$jsData = json_encode($data);

// ...

    'form_params' => $jsonData
您只需将数据作为数组传递,而无需通过json_encode运行:


我现在收到了这个错误-解码JSON对象失败:没有JSON对象可以被解码如果你把dd$call->getBody->getContents;放在你的JSON\u解码行之前,你会看到什么?同样的错误-解码JSON对象失败:没有JSON对象可以被解码。在做了这些更改之后,你能用你的代码当前的样子更新你的问题吗?你能把完整的错误也添加到问题中吗?在编辑部分的代码块下面。
$data = ["name" => "joe doe"];
$jsData = json_encode($data);

// ...

    'form_params' => $jsonData
$data = ["name" => "joe doe"];

// ...

$call = $this->client->post(env('URL'), [
    "headers" => $headers,
    'form_params' => $data
]);