简体   繁体   中英

Receiving a POST Request on Spring From Another Site

I'm a little new in Java Spring. What I want to do is as follows: Some 3rd party is asking a "return URL" from me and I set it as follows: https://localhost:9002/my-account/order-history Then they send me a POST request and I'm supposed to handle it within my controller. The request has both url parameters and a form data. The request is

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

A part of the form data is:

I added the whole form data and other request info as attachment .

The controller I'm desperately trying to use is as follows:

@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");
    }
    ....
}

And I keep getting 403 - Bad or missing CSRF token error. How should I implement my controller? I have checked below links and they did not work out unfortunately: How to retrieve FORM/POST Parameters in Spring Controller? How to explicitly obtain post data in Spring MVC?

I tried, but failed to regenerate issue on postman. Can anyone, please, advise me about how to move on?

you can annotate your method with @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");
}

https://spring.io/guides/gs/rest-service-cors/

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