AffirmPaymentController的请求方法’POST’不受支持。

huangapple go评论80阅读模式
英文:

AffirmPaymentController Request method 'POST' not supported

问题

下面是我拥有的方法:

  1. @RequestMapping(value = "/authorise", method = {RequestMethod.POST, RequestMethod.GET})
  2. public String authorise(@RequestParam(name = "checkout_token", required = false) final String checkoutToken,
  3. final Model model, final RedirectAttributes redirectModel) {
  4. boolean success = false;
  5. try {
  6. success = affirmPaymentFacade.authorisePayment(checkoutToken);
  7. } catch (RuntimeException re) {
  8. LOG.warn("error during payment authorisation", re);
  9. }
  10. if (success) {
  11. final OrderData orderData;
  12. try {
  13. orderData = getCheckoutFacade().placeOrder();
  14. } catch (final Exception e) {
  15. LOG.error("Failed to place Order", e);
  16. //TODO-BE auth reversal
  17. //GlobalMessages.addErrorMessage(model, "checkout.affirm.order.failed");
  18. return REDIRECT_PREFIX + CHECKOUT_AFFIRM_ERROR;
  19. }
  20. return redirectToOrderConfirmationPage(orderData);
  21. } else {
  22. //GlobalMessages.addErrorMessage(redirectModel, "checkout.affirm.authorisation.failed");
  23. return REDIRECT_PREFIX + CHECKOUT_AFFIRM_ERROR;
  24. }
  25. }

当调用 GET 请求时,它正常工作,但当我们使用 POST 请求并附带请求负载 checkout_token=XXXX 时,我得到以下错误:

WARN [hybrisHTTP24] [DefaultHandlerExceptionResolver] 已解决
[org.springframework.web.HttpRequestMethodNotSupportedException:
不支持请求方法 'POST']

编辑

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

英文:

Below is the method that I have

  1. @RequestMapping(value = "/authorise", method = {RequestMethod.POST,RequestMethod.GET})
  2. public String authorise(@RequestParam(name = "checkout_token", required = false) final String checkoutToken,
  3. final Model model, final RedirectAttributes redirectModel) {
  4. boolean success = false;
  5. try
  6. {
  7. success = affirmPaymentFacade.authorisePayment(checkoutToken);
  8. }
  9. catch (RuntimeException re)
  10. {
  11. LOG.warn("error during payment authorisation ", re);
  12. }
  13. if(success){
  14. final OrderData orderData;
  15. try
  16. {
  17. orderData = getCheckoutFacade().placeOrder();
  18. }
  19. catch (final Exception e)
  20. {
  21. LOG.error("Failed to place Order", e);
  22. //TODO-BE auth reversal
  23. //GlobalMessages.addErrorMessage(model, "checkout.affirm.order.failed");
  24. return REDIRECT_PREFIX + CHECKOUT_AFFIRM_ERROR;
  25. }
  26. return redirectToOrderConfirmationPage(orderData);
  27. }else {
  28. //GlobalMessages.addErrorMessage(redirectModel,"checkout.affirm.authorisation.failed");
  29. return REDIRECT_PREFIX + CHECKOUT_AFFIRM_ERROR;
  30. }
  31. }

When GET request is called its working fine but when we call with POST request and request payload
checkout_token=XXXX, I am getting below error

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

EDIT

Even I tried with removing all parameters but still no luck so far.

答案1

得分: 1

首先,关于在StackOverflow上更好地发布问题的一些信息:

  • 将问题简化为最紧凑的代码(如果您在方法中的代码与问题无关,只要您遇到了与方法路由相关的问题)
  • 这不仅仅是一个Hybris的问题,因为使用了Spring MVC。在Spring MVC论坛上,您会获得比在Hybris的StackOverflow上获得更多的回答。
  • 请包含您的导入语句

关于这段代码:

  1. package com.example.demo;
  2. import org.springframework.ui.Model;
  3. import org.springframework.web.bind.annotation.RequestMapping;
  4. import org.springframework.web.bind.annotation.RequestMethod;
  5. import org.springframework.web.bind.annotation.RequestParam;
  6. import org.springframework.web.bind.annotation.RestController;
  7. import org.springframework.web.servlet.mvc.support.RedirectAttributes;
  8. @RestController
  9. public class TestController
  10. {
  11. @RequestMapping(value = "/authorise", method = { RequestMethod.POST, RequestMethod.GET })
  12. public String authorise(@RequestParam(name = "checkout_token", required = false) final String checkoutToken,
  13. final Model model, final RedirectAttributes redirectModel)
  14. {
  15. return "authorise";
  16. }
  17. }

该方法可通过GET和POST方法访问:

  1. curl -X GET http://localhost:9080/authorise
  2. >> authorise
  3. curl -X POST http://localhost:9080/authorise
  4. >> authorise
  5. 也许您正在尝试使用错误的URL
英文:

Firstly a little information about better posting on StackOverflow:

  • Reduce your problem to the compactest possible code (Your code in the method does not matter, if you are having problems with the routing to the method)
  • This is not a hybris only problem as Spring MVC is used. You will get a lot more answers in a spring mvc forum as in a Hybris stackoverflow.
  • Please include your imports

With this code:

  1. package com.example.demo;
  2. import org.springframework.ui.Model;
  3. import org.springframework.web.bind.annotation.RequestMapping;
  4. import org.springframework.web.bind.annotation.RequestMethod;
  5. import org.springframework.web.bind.annotation.RequestParam;
  6. import org.springframework.web.bind.annotation.RestController;
  7. import org.springframework.web.servlet.mvc.support.RedirectAttributes;
  8. @RestController
  9. public class TestController
  10. {
  11. @RequestMapping(value = "/authorise", method = { RequestMethod.POST, RequestMethod.GET })
  12. public String authorise(@RequestParam(name = "checkout_token", required = false) final String checkoutToken,
  13. final Model model, final RedirectAttributes redirectModel)
  14. {
  15. return "authorise";
  16. }
  17. }

}

The method is accessible by GET and POST:

  1. curl -X GET http://localhost:9080/authorise
  2. >> authorise
  3. curl -X POST http://localhost:9080/authorise
  4. >> authorise

Maybe you are trying to use the wrong url?

答案2

得分: 0

尝试为此URL禁用CSRF令牌

英文:

Try to disable csrf token for this url

huangapple
  • 本文由 发表于 2020年8月19日 21:22:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/63487974.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定