仅为单一方法删除 csrf 令牌 - Laravel
Remove csrf token only for single method - Laravel
我正在使用 paytabs 支付网关 api。在那个 api 中,必须给出重定向 url,这样一旦交易完成,页面将自动重定向到您给定的重定向 url。 url 是 GET url,但由于 api 的响应是 POST 类型,我无法使用 get url。为了解决这个问题,我将该路由设置为 POST url 但是通过将其设置为 post 方法,我没有获得任何 CSRF 令牌。最后,我得到了这个问题。
TokenMismatchException in VerifyCsrfToken.php line 68:
有什么方法可以仅针对单个 POST url 禁用 CSRF 令牌功能?
--已尝试建议--
我按照你的建议做了这个
class VerifyCsrfToken extends Middleware
{
protected $except = [
'signup/complete',
];
}
现在
Class 'Middleware' not found
来自the docs:
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:
class VerifyCsrfToken extends Middleware
{
protected $except = [
'stripe/*',
'http://example.com/foo/bar',
'http://example.com/foo/*',
];
}
您可以在 csrf 中间件中排除。转到 app/http/Middleware/VirefyCsrfToken.php
class VerifyCsrfToken extends BaseVerifier{
protected $except = [
'route url1',
'route url2',
]
}
了解如何使用 localhost
在你的项目文件夹 /app/http/middleware/VerifyCsrfToken.php 编辑
protected $except = [
//
'http://localhost/blog/return_url', // your url
];
我正在使用 paytabs 支付网关 api。在那个 api 中,必须给出重定向 url,这样一旦交易完成,页面将自动重定向到您给定的重定向 url。 url 是 GET url,但由于 api 的响应是 POST 类型,我无法使用 get url。为了解决这个问题,我将该路由设置为 POST url 但是通过将其设置为 post 方法,我没有获得任何 CSRF 令牌。最后,我得到了这个问题。
TokenMismatchException in VerifyCsrfToken.php line 68:
有什么方法可以仅针对单个 POST url 禁用 CSRF 令牌功能?
--已尝试建议-- 我按照你的建议做了这个
class VerifyCsrfToken extends Middleware
{
protected $except = [
'signup/complete',
];
}
现在
Class 'Middleware' not found
来自the docs:
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 theVerifyCsrfToken
middleware:
class VerifyCsrfToken extends Middleware
{
protected $except = [
'stripe/*',
'http://example.com/foo/bar',
'http://example.com/foo/*',
];
}
您可以在 csrf 中间件中排除。转到 app/http/Middleware/VirefyCsrfToken.php
class VerifyCsrfToken extends BaseVerifier{
protected $except = [
'route url1',
'route url2',
]
}
了解如何使用 localhost 在你的项目文件夹 /app/http/middleware/VerifyCsrfToken.php 编辑
protected $except = [
//
'http://localhost/blog/return_url', // your url
];