简体   繁体   English

自定义 Shopware6 路由给出“405 Method Not Allowed”

[英]custom Shopware6 route gives “405 Method Not Allowed”

I created a shopware6 plugin which includes a frontend custom route which should be able to receive POST requests from ExactOnline.我创建了一个shopware6插件,其中包含一个前端自定义路由,它应该能够接收来自 ExactOnline 的 POST 请求。

But when I make some tests with Postman, I receive " 405 Method Not allowed ".但是当我用 Postman 进行一些测试时,我收到“ 405 Method Not allowed ”。 Here is my controller:这是我的 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';

        }

    }

When I replace the methods={"POST"} by methods={"GET"} , the same test request returns "ok boy" which is normal.当我将methods={"POST"}替换为 methods= {"GET"}时,相同的测试请求返回“ok boy”,这是正常的。

I had already created a plugin like this in Shopware5 and GET and POST requests were already working without doing anything special.我已经在Shopware5中创建了一个这样的插件,并且GETPOST请求已经可以正常工作,而无需做任何特别的事情。

How to make POST requests ALLOW in my case on Shopware6 ?在我的情况下,如何在Shopware6发出POST请求?

Thanks !谢谢 !

You have limited the route to POST.您已将路线限制为 POST。 When you call it from another Method then POST, it will result in Method not allowed error.当您从另一个方法调用它然后 POST 时,将导致 Method not allowed 错误。 Maybe you want to whitelist both GET and POST?也许您想将 GET 和 POST 都列入白名单?

So change it to methods={"GET", "POST"}所以把它改成methods={"GET", "POST"}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM