gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 09:56:29 25 4
gpt4 key购买 nike

我创建了一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com