Guzzle post 请求导致 400 错误请求

Guzzle post request result in a 400 Bad Request

我是 google 驱动器 api 的新手。 当我 运行 下面的代码(我从 here 得到它)时,我得到以下错误:

Fatal error: Uncaught exception 'GuzzleHttp\Exception\ClientException' with message 'Client error: POST https://spreadsheets.google.com/feeds/list/1AnZ9_h3jnKogvx5AIftxypGnGM0f2P4r_ut4RGFC7AQ/od6/private/full resulted in a 400 Bad Request response'

代码:

$postBody = '<entry xmlns="http://www.w3.org/2005/Atom"       xmlns:gsx="http://schemas.google.com/spreadsheets/2006/extended"><gsx:gear>more gear</gsx:gear><gsx:quantity>44</gsx:quantity></entry>';
echo "BBBB<br>";
$httpClient = new GuzzleHttp\Client(['headers' => $headers]);
echo "CCCC<br>";
$resp = $httpClient->request($method, $url, ['body' => $postBody]);
echo "DDDD<br>";
$body = $resp->getBody()->getContents();
$code = $resp->getStatusCode();
$reason = $resp->getReasonPhrase();
echo "$code : $reason\n\n";
echo "$body\n";

谁能帮我找出错误?

虽然这与 Guzzle 完全无关,但我找到了另一种方法来完成我的任务。 创建表单后,转到 Responses 菜单和 select 'Get pre-filled URL'

填写您收到的虚拟表格并提交。然后你会得到一个URL。这里把'viewResponse'改成'formResponse'

将数据附加到 URL 的必要部分。 向此 URL 发送请求以自动填写 google 表格并提交