英文:
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] 已解决
[org.springframework.web.HttpRequestMethodNotSupportedException:
不支持请求方法 'POST']
编辑
即使我尝试删除所有参数,到目前为止仍然没有成功。
英文:
Below is the method that I have
@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;
}
}
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上获得更多的回答。
- 请包含您的导入语句
关于这段代码:
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?
英文:
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:
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";
}
}
}
The method is accessible by GET and POST:
curl -X GET http://localhost:9080/authorise
>> authorise
curl -X POST http://localhost:9080/authorise
>> authorise
Maybe you are trying to use the wrong url?
答案2
得分: 0
尝试为此URL禁用CSRF令牌
英文:
Try to disable csrf token for this url
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论