samedi 30 avril 2016

Guzzle Post Request getting ERR_INVALID_CHUNKED_ENCODING when trying to access the request in controller

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(request());
}

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!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire