【问题标题】:Why do I get a 301 response on HTTP post to Laravel without CSRF token?为什么我在没有 CSRF 令牌的情况下对 Laravel 的 HTTP 发布收到 301 响应?
【发布时间】:2020-03-11 14:43:05
【问题描述】:

我正在尝试在我的网店中设置 Adyen 通知。
https://docs.adyen.com/development-resources/notifications/understand-notifications

当我使用 Adyen 测试页面测试 HTTP 帖子时,我收到 301 响应,但是当我使用自定义表单测试 HTTP 帖子时,路由有效。

web.php 中的路由:
Route::name('shop.checkout.adyen-notification')->post('/adyen-notification', 'Shop\CheckoutController@adyenNotification');

VerifyCsrfToken.php 中的设置:
protected $except = ['*/adyen-notification?*'];

自定义表单:

<form method="post" action="https://example.com/adyen-notification?originalReference=&reason=&merchantAccountCode=Test&eventCode=NOTIFICATIONTEST&operations=&success=true&paymentMethod=bankTransfer_BE&currency=EUR&pspReference=test_NOTIFICATIONTEST_1&merchantReference=testMerchantRef1&value=11099">
    <input type="submit" value="SUBMIT">
</form>

我不知道为什么它给我一个 301 响应。

【问题讨论】:

  • 301 表示“永久移动”。由于您将 CSRF 令牌列入白名单,而我们看不到您的控制器做了什么,我们不知道您应该得到什么响应。您期望得到什么回应?
  • @LobsterBaz 我的控制器只返回一个字符串 atm 时刻进行测试。当我提交我提到的表单时,它返回的字符串很好,但是当我从 Adyen 测试页面发送 HTTP 帖子时,我得到 301 响应。
  • 301 是状态,响应中有数据吗?既然是重定向状态,那么重定向到哪里呢?我对 Adyen 不熟悉,但它可能与您不使用 https 的本地环境有关吗?
  • @LobsterBaz 它从 Laravel 返回默认的 301 html,并说它移动到了与我调用相同的 url。我的开发环境使用 https。
  • 我从未使用过 Adyen,但您是否需要使用测试 API 密钥进入测试模式?可以从 Internet 访问您的开发服务器吗?你的 Laravel .env APP_URL 是否与你的服务器 URL 匹配?

标签: php laravel http post adyen


【解决方案1】:

您的表单操作中有错字,缺少右引号:

<form method="post" action="https://example.com/adyen-notification?originalReference=&reason=&merchantAccountCode=Test&eventCode=NOTIFICATIONTEST&operations=&success=true&paymentMethod=bankTransfer_BE&currency=EUR&pspReference=test_NOTIFICATIONTEST_1&merchantReference=testMerchantRef1&value=11099>
    <input type="submit" value="SUBMIT">
</form>

应该是:

<form method="post" action="https://example.com/adyen-notification?originalReference=&reason=&merchantAccountCode=Test&eventCode=NOTIFICATIONTEST&operations=&success=true&paymentMethod=bankTransfer_BE&currency=EUR&pspReference=test_NOTIFICATIONTEST_1&merchantReference=testMerchantRef1&value=11099">
    <input type="submit" value="SUBMIT">
</form>

【讨论】:

  • 我在这里粘贴错了,但没关系。我的自定义表单有效,所以这不是问题。只有当我从 Adyen 发帖时,我才会收到 301 响应。
猜你喜欢
  • 2019-02-20
  • 2019-08-13
  • 1970-01-01
  • 2012-11-03
  • 2015-04-09
  • 1970-01-01
  • 1970-01-01
  • 2021-09-03
  • 1970-01-01
相关资源
最近更新 更多