php - 自定义 Shopware6 路由给出 "405 Method Not Allowed"

标签 php post plugins controller shopware

我创建了一个 shopware6 插件,其中包含一个前端自定义路由,该路由应该能够接收来自 ExactOnline 的 POST 请求。

但是当我使用 Postman 进行一些测试时,我收到“405 Method Not allowed”。 这是我的 Controller :

<?php

namespace Emakers\TransmissionPlugin\Controller;

//use Emakers\TransmissionPlugin\Controller\Frontend\Services\ExactRequirements;
use Shopware\Core\Framework\Routing\Annotation\RouteScope;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Storefront\Controller\StorefrontController;
use Symfony\Component\Routing\Annotation\Route;


/**
 * @RouteScope(scopes={"storefront"})
 */
class AccountsController extends StorefrontController
{

    /**
     * @Route("/accounts", name="frontend.accounts", options={"seo"="false"}, methods={"POST"})
     */
    public function accounts()
    {
        die('ok boy');
        $file    = 'custom/plugins/TransmissionPlugin/Resources/webhooks/accountWebhook.txt';

        }

    }

当我用 methods={"GET"} 替换 methods={"POST"} 时,相同的测试请求返回正常的“ok boy”。

我已经在 Shopware5 中创建了一个这样的插件,并且 GETPOST 请求已经可以正常工作而无需执行任何特殊操作。

在我的案例中,如何在 Shopware6 上发出POST 请求ALLOW

谢谢!

最佳答案

您已将路由限制为 POST。当您从另一个方法调用它然后 POST 时,它会导致 Method not allowed 错误。也许您想将 GET 和 POST 都列入白名单?

所以把它改成methods={"GET", "POST"}

关于php - 自定义 Shopware6 路由给出 "405 Method Not Allowed",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61908567/

相关文章:

php - 不将重复项插入 MySQL DB - Doctrine 和 Symfony2

c# - HttpWebRequest 不发送 +(加号)字符

python - 如何同时使用多个 .mo 文件进行 gettext 翻译?

php - cURL - 加载具有 CloudFlare 保护的网站

php - MySQL、PHP;在比较之前编辑列值

.htaccess - 限制 POST 请求服务器

java - 如何将 Webwork 操作添加到项目面板?

plugins - 在 Jenkins docker 容器中使用 docker build step 插件

php - MySQL:用另一个表中的行替换一个表中的行

.htaccess - 为什么在 .htaccess 中使用 [QSA] 时 $_POST 为空?