gpt4 book ai didi

laravel - 检测从 Postman 发送的请求

转载 作者:行者123 更新时间:2023-12-01 21:35:27 25 4
gpt4 key购买 nike

我想请求使用 laravel 验证人们的 ID。因为它是非常有凭据的,所以我只想在他们通过手机验证它时才提供它。
所以一定要防止 postman 请求验证ID。
有没有办法检测请求是否来自 postman ?

如有任何想法,我们将不胜感激 :)。
先谢谢你

最佳答案

Postman 倾向于发送一个名为 postman-token 的 header ,因此如果存在这样的 header ,您可以阻止请求。

编辑 请注意,可以在 postman 设置中关闭此 header

正如@EdwardChew 所写,这不会阻止人们使用 postman/curl/python/其他任何东西。向端点添加身份验证是最好的方法。

示例 postman 请求:

GET /api/car HTTP/1.1
Host: localhost:8080
Content-Type: application/json
cache-control: no-cache
Postman-Token: 05f5c492-3697-41b1-be0f-fb9bc4499b96

由于 postman 具有“代码”功能,如果请求被阻止,很容易将其复制为 curl 命令:

curl -X GET \
http://localhost:8080/api/car \
-H 'Content-Type: application/json' \
-H 'Postman-Token: e37790ea-a3a5-40cf-ac4c-b80184801f94' \
-H 'cache-control: no-cache'

并且只删除带有 Postman-Token header 的行。我通常在试验 API 时这样做。

如果您查看 Laravel 文档,有一个关于授权的部分:https://laravel.com/docs/5.8/api-authentication这将强制用户添加像这样的 header token :Authorization: Bearer 8fyew8f9yefo7o9yg98gyr 然后您就可以验证调用者

关于laravel - 检测从 Postman 发送的请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62014300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com