Why does the Laravel API return a 419 status code on POST and PUT methods?

后端 未结 3 1185
攒了一身酷
攒了一身酷 2020-11-28 13:12

I am trying to create a RESTful API by using Laravel. I have created my controller using php artisan make:controller RestController and this is my controlle

3条回答
  •  借酒劲吻你
    2020-11-28 13:45

    if you are developing rest apis better not to add token .if you are using 5.4 or 5.5 you can use api.php instead of web.php .In api.php you dont need token verifcation on post request.

    if you are using web.php then you exculde token .Here is the official documentation

    Excluding URIs From CSRF Protection

    Sometimes you may wish to exclude a set of URIs from CSRF protection. For example, if you are using Stripe to process payments and are utilizing their webhook system, you will need to exclude your Stripe webhook handler route from CSRF protection since Stripe will not know what CSRF token to send to your routes.

    Typically, you should place these kinds of routes outside of the web middleware group that the RouteServiceProvider applies to all routes in the routes/web.php file. However, you may also exclude the routes by adding their URIs to the $except property of the VerifyCsrfToken middleware:

    for reference

    https://laravel.com/docs/5.5/csrf

提交回复
热议问题