我创建了一个 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 中创建了一个这样的插件,并且 GET 和 POST 请求已经可以正常工作而无需执行任何特殊操作。
在我的案例中,如何在 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/