我在Java Spring中有点新鲜。我想做的是如下: 有些第三方正在询问"返回网址"从我和我的设置如下: https://localhost:9002/my-account/order-history 然后他们发给我一个POST请求,我应该在我的控制器中处理它。该请求包含url参数和表单数据。请求是
Request URL:https://localhost:9002/my-account/order-history?responseCode=0000&token=E0ECFC1214B19E5D11B9B587920FC5F164C5CB17E7DC67F083E0EC6676F79467DFBDF4B6CCF3C39BF47F0232D1AA42F1FA112F29B0157DDF98EE3997F781CCB1FEB070A44E530691BA36674BEA4CF56A4A43F2B9746D9C3591CF288D745A6694
Request Method:POST
Status Code:403 Bad or missing CSRF token
Remote Address:127.0.0.1:9002
Referrer Policy:no-referrer-when-downgrade
我将整个表单数据和其他请求信息添加为attachment。
我迫切想要使用的控制器如下:
@Controller
@RequestMapping(value = "/my-account")
public class MaviAccountPageController extends MaviAbstractController
{
@RequestMapping(value = "/order-history", method = RequestMethod.POST)
public ModelAndView process(@RequestBody final String req)
{
//consumes = "text/plain"
System.out.println(req);
System.out.println(req);
return new ModelAndView("deneme");
}
....
}
我一直收到403 - 错误或错过了CSRF令牌错误。 我应该如何实现我的控制器?我检查了下面的链接,不幸的是他们没有成功: How to retrieve FORM/POST Parameters in Spring Controller? How to explicitly obtain post data in Spring MVC?
我试过,但未能在邮递员身上重新生成问题。 有人可以告诉我如何继续前进吗?
答案 0 :(得分:0)
您可以使用@CrossOrigin
注释您的方法@CrossOrigin
@RequestMapping(value = "/order-history", method = RequestMethod.POST)
public ModelAndView process(@RequestBody final String req)
{
//consumes = "text/plain"
System.out.println(req);
System.out.println(req);
return new ModelAndView("deneme");
}