自定义Shopware6路由显示“405方法不允许”。

3
我创建了一个包含前端自定义路由的shopware6插件,应该可以接收ExactOnline的POST请求。但是当我用Postman进行一些测试时,我收到了“405方法不允许”的错误提示。 以下是我的控制器代码:
<?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={"POST"} 替换为 methods={"GET"} 后,相同的测试请求返回了正常的 "ok boy"。

我之前在 Shopware5 中创建过类似的插件,GETPOST 请求已经可以正常工作,不需要做任何特殊处理。

如何在我的情况下使 POST 请求被 ALLOWShopware6 上运行?

谢谢!

1个回答

5
你将路由限制为只能使用POST方法。如果你从其他请求方法调用它,就会导致“不允许的方法”错误。也许你想同时支持GET和POST方法?所以把它改成methods={"GET", "POST"}。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接