dongmei1988 2016-01-19 01:50
浏览 732
已采纳

Guzzle发布请求导致400 Bad Request

I'm new to google drive api. When I run the following piece of code (I got it from here) I get the following error:

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'

The code:

$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

";
echo "$body
";

Can some one help me find the error?

  • 写回答

1条回答 默认 最新

  • drox90250557 2016-01-26 02:06
    关注

    Although this is not related to Guzzle at all, I found another method to do my task. After creating the form go to Responses menu and select 'Get pre-filled URL'

    Fill the dummy form you get and submit. Then you will be given a URL. Here change 'viewResponse' to 'formResponse'

    Append the data to necessary parts of the URL. Send request to this URL to fill the google form automatically and submit

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部