我有一个登录帖子请求。
@RequestMapping(value = EWPRestContants.DO_LOGIN, method = RequestMethod.POST, consumes=MediaType.APPLICATION_XML_VALUE,produces=MediaType.TEXT_PLAIN_VALUE)
public ResponseEntity<String> doLogin(@RequestBody Loginrequest logReq,@RequestHeader HttpHeaders headers, HttpServletRequest request, HttpServletResponse httpResponse) throws Exception {
//........
}
我想从标题中提取数据。有API可以吗?
假设我的标题包含客户msIsdn编号和名称。我如何获取这些细节。 getFirst()用于获取用户代理详细信息或仅用于起始行。
这就是答案。
String id= headers.getFirst("ID");
答案 0 :(得分:1)
喜欢
@RequestHeader(value =&#34; User-Agent&#34;,defaultValue =&#34; foo&#34;)String userAgent
@RequestMapping(value = EWPRestContants.DO_LOGIN, method = RequestMethod.POST, consumes=MediaType.APPLICATION_XML_VALUE,produces=MediaType.TEXT_PLAIN_VALUE)
public ResponseEntity<String> doLogin(@RequestBody Loginrequest logReq,@RequestHeader(value="User-Agent", defaultValue="foo") String userAgent,@RequestHeader(value="Accept-Language") String acceptLanguage, HttpServletRequest request, HttpServletResponse httpResponse) throws Exception {
//........
}
或来自
@RequestMapping(value = EWPRestContants.DO_LOGIN, method = RequestMethod.POST, consumes=MediaType.APPLICATION_XML_VALUE,produces=MediaType.TEXT_PLAIN_VALUE)
public ResponseEntity<String> doLogin(@RequestBody Loginrequest logReq,@RequestHeader HttpHeaders headers, HttpServletRequest request, HttpServletResponse httpResponse) throws Exception {
String userAgent = headers.getFirst(HttpHeaders.USER_AGENT);
}