不支持 AffirmPaymentController 请求方法 'POST'

AffirmPaymentController Request method 'POST' not supported

下面是我的方法

@RequestMapping(value =  "/authorise", method = {RequestMethod.POST,RequestMethod.GET})
   public String authorise(@RequestParam(name = "checkout_token", required = false) final String checkoutToken,
         final Model model, final RedirectAttributes redirectModel) {

      boolean success = false;

      try
      {
         success = affirmPaymentFacade.authorisePayment(checkoutToken);
      }
      catch (RuntimeException re)
      {
         LOG.warn("error during payment authorisation ", re);
      }
      if(success){
         final OrderData orderData;
         try
         {
            orderData = getCheckoutFacade().placeOrder();
         }
         catch (final Exception e)
         {
            LOG.error("Failed to place Order", e);
            //TODO-BE auth reversal
            //GlobalMessages.addErrorMessage(model, "checkout.affirm.order.failed");
            return REDIRECT_PREFIX + CHECKOUT_AFFIRM_ERROR;
         }

         return redirectToOrderConfirmationPage(orderData);
      }else {
         //GlobalMessages.addErrorMessage(redirectModel,"checkout.affirm.authorisation.failed");
         return REDIRECT_PREFIX + CHECKOUT_AFFIRM_ERROR;
      }
   }

当调用 GET 请求时它工作正常但是当我们调用 POST 请求和请求负载时 checkout_token=XXXX,我遇到以下错误

WARN [hybrisHTTP24] [DefaultHandlerExceptionResolver] Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported]

编辑

即使我尝试删除所有参数,但到目前为止仍然没有成功。

首先是关于更好地在 Whosebug 上发帖的一些信息:

  • 将您的问题减少到尽可能紧凑的代码(如果您在方法的路由方面遇到问题,则方法中的代码无关紧要)
  • 这不是 hybris 独有的问题,因为使用了 Spring MVC。您将在 spring mvc 论坛和 Hybris Whosebug 中获得更多答案。
  • 请包括您的导入

使用此代码:

package com.example.demo;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;


@RestController
public class TestController
{
    @RequestMapping(value = "/authorise", method = { RequestMethod.POST, RequestMethod.GET })
    public String authorise(@RequestParam(name = "checkout_token", required = false) final String checkoutToken,
            final Model model, final RedirectAttributes redirectModel)
    {
        return "authorise";
    }
}

}

该方法可通过 GET 和 POST:

访问
curl -X GET http://localhost:9080/authorise
>> authorise

curl -X POST http://localhost:9080/authorise
>> authorise

可能你用错了url?

尝试禁用此 url

的 csrf 令牌