1
votes

I am trying to send post data and retrieve them in the response. I look online and found guzzle, so there is what I've done :

The controller part I wan't to call on route 'test' :

public function test(Request $request) {
    return $request->input('test');
}

public function sinistre(Client $client) {
    $request = $client->post(route('test') , [], [
        'form_params' => [
            'test' => 'edf'
        ]
    ]);

    $response = $request->send();

    dd($response);

    return "ok";
}

Version of guzzle : "guzzlehttp/guzzle": "^6.2"

For now I only got a 500 error response.

1
can you share dd(route('test'));Anar Bayramov
do you have this endpoint ?Anar Bayramov
In web.php : Route::post('/test', 'HomeController@test') ->name('test');Neok
I mean do you have an api response on this endpoint?Anar Bayramov

1 Answers

3
votes

Laravel requires a CSRF token to be sent along with the request as it is a post request, so you can either exclude it or get a new token by using csrf_token()

Optionally as per the demo, you can exclude URI's from needing it

    <?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;

class VerifyCsrfToken extends BaseVerifier
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        'test/*',
    ];
}

You would of course need to update the $except URI with yours.