如何在 Spring 控制器中检索 FORM/POST 参数?

2023-11-22

我有以下回应,应该来自邮件黑猩猩网络钩子 URL。

这是行正文:

RAW BODY

    type=usub&fired_at=2015-07-23+17%3A19%3A34&data%5Baction%5D=unsub&data%5Breason%5D=manual&data%5Bid%5D=9383uy636&data%5Bemail%5D=youremail%40YOURDOMAIN.com&data%5Bemail_type%5D=html&data%5Bip_opt%5D=202.9.3.003&data%5Bweb_id%5D=404004&data%5Bmerges%5D%5BEMAIL%5D=YOUREMAIL%40YOURDOMAIN.com&data%5Bmerges%5D%5BFNAME%5D=NAME&data%5Bmerges%5D%5BLNAME%5D=LASTNAME&data%5Blist_id%5D=2288883
 FORM/POST PARAMETERS

fired_at: 2015-07-22 12:19:34
data[email]: [email protected]
data[id]: 56775409ta
data[web_id]: 09833944
data[merges][EMAIL]: [email protected]
type: unsub
data[list_id]: 99884hy372
data[merges][FNAME]: Name
data[ip_opt]: 202.0.9.3333
data[reason]: manual
data[email_type]: html
data[action]: unsub
data[merges][LNAME]: LastName

**QUERYSTRING key: a4483983hu473004884j0x**

HEADERS

Accept: */*
Total-Route-Time: 0
Host: requestb.in
Connection: close
Content-Length: 395
User-Agent: MailChimp.com
Connect-Time: 0
Via: 1.1 vegur
X-Request-Id: 6633d8-653e-4cea-884j-9933ju4773h
Content-Type: application/x-www-form-urlencoded

我用过@RequestParameter以前在使用 Spring 控制器时,但是我不确定如何从上述响应中获取数据,例如数据[合并][名称]:

我怎样才能在 Spring 控制器中获取 QueryString ?查询字符串键:a4483983hu473004884j0x

//I have the following code to begin with
@RequestMapping("/unsubscribewebhook")
    public ZapJasonMessage unsubscribeWebHook(
    @RequestParam("key") String key,
    @RequestParam ("data[merges][FNAME]") String firstName
) {

}

我感谢您的帮助!


您只需将 WebRequest 作为参数注入到控制器 POST 方法中,然后使用 Mailchimp Webhook 中的给定参数请求 getParameter()。

e.g:

@RequestMapping(path="/MyUrl", method=RequestMethod.POST)
public ModelAndView process(WebRequest request){
    System.out.println(request.getParameter("type"));
    System.out.println(request.getParameter("data[merges][EMAIL]"));
    return new ModelAndView([YOURVIEWHERE]);
}

就这样...

Regards.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 Spring 控制器中检索 FORM/POST 参数? 的相关文章

随机推荐