简体   繁体   中英

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.

But when I make some tests with Postman, I receive " 405 Method Not allowed ". Here is my 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.

I had already created a plugin like this in Shopware5 and GET and POST requests were already working without doing anything special.

How to make POST requests ALLOW in my case on Shopware6 ?

Thanks !

You have limited the route to POST. When you call it from another Method then POST, it will result in Method not allowed error. Maybe you want to whitelist both GET and POST?

So change it to methods={"GET", "POST"}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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