簡體   English   中英

自定義 Shopware6 路由給出“405 Method Not Allowed”

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

我創建了一個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={"POST"}替換為 methods= {"GET"}時,相同的測試請求返回“ok boy”,這是正常的。

我已經在Shopware5中創建了一個這樣的插件,並且GETPOST請求已經可以正常工作,而無需做任何特別的事情。

在我的情況下,如何在Shopware6發出POST請求?

謝謝 !

您已將路線限制為 POST。 當您從另一個方法調用它然后 POST 時,將導致 Method not allowed 錯誤。 也許您想將 GET 和 POST 都列入白名單?

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM