返回GuzzleHttp响应对象会导致浏览器中出现ERR_INVALID_CHUNKED_ENCODING

I'm using guzzle 6 in laravel 5 to send a post request but I'm getting ERR_INVALID_CHUNKED_ENCODING when I try to access the request() in the method that handles the post request.

Here's my code:

Routes.php

Route::get('/guzzle', [
    'as'   => 'guzzle-test',
    'uses' => 'TestController@getTest'
]);

Route::post('/guzzle', [
   'as'   => 'guzzle-post-test',
   'uses' => 'TestController@postTest'
]);

TestController.php

public function getTest()
{
    $client = new Client();

    $data = [
        'hey' => 'ho'
    ];

    $request = $client->post(route('guzzle-post-test'), [
        'content-type' => 'application/json'
    ], json_encode($data));

    return $request;
}

public function postTest()
{
    dd(getTest());
}

I getting to the post request handler since I've tried to diedump a string and it gets there, but if i call the request() I get that error. For what I've researched It may have something to with the content length, but after reading guzzle's docs and some stuff around the web I could find how to get and pass the content length appropriately in the request. Any help would be very appreciated!

查看全部
douchou8935
douchou8935
2016/04/30 16:15
  • laravel
  • http
  • php
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复