Laravel Sanctum 和 Postman 的 POST 请求问题 [英] Issue with POST requests with Laravel Sanctum and Postman

查看:36
本文介绍了Laravel Sanctum 和 Postman 的 POST 请求问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对与这篇文章相关的 Sanctum 和 Postman 有疑问:

解决方案

我一直在我的一个电子商务 API 中使用 sanctum,并且我也遵循了与您相同的教程在问题中链接.很难说出您的实际问题是什么,但您似乎没有在 POST 请求中发送 X-XSRF-TOKEN 标头.

最后一段在上述教程中,作者展示了如何点击 /logout 路由,这是一个 POST 路由.

I have a problem with Sanctum and Postman that's related to this post: SPA Authentication Issues with Sanctum and Postman

I followed everything from the Laravel docs about Sanctum and configured it correctly. Then I followed this tutorial: https://blog.codecourse.com/laravel-sanctum-airlock-with-postman/

Everything is working except for POST requests. When I do login, it works. But then I have a collection without the pre-request Script and when I do a GET request to for example /user, it will return the logged in user.

But when I change the method to POST in Laravel and in Postman, I'll get a CSRF token mismatch error.

Does anybody knows what I have to do, to make POST requests working?

Route::middleware('auth:sanctum')->post('/user', function (Request $request) {
    return $request->user();
});

解决方案

I've been using sanctum in one of my e-commerce APIs and I've also followed the same tutorial you've linked in the question. It's hard to tell what's the actual problem in your case but it seems like that you're not sending the X-XSRF-TOKEN header in your POST requests.

The last paragraph in the above-mentioned tutorial, the writer shows how to hit the /logout route which is a POST route.

这篇关于Laravel Sanctum 和 Postman 的 POST 请求问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆