两种获取Header的方式:
原始方式:
@RestController
@RequestMapping("/param")
public class ParamController {//如何获取Header@RequestMapping("/getHeader")public String getHeader(HttpServletRequest request){String userAgent = request.getHeader("User-Agent");return "User-Agent: "+userAgent;}}
在浏览器输入:localhost:8080/param/getHeader
最新方式:
@RequestMapping("/getHeader2")public String getHeader2(@RequestHeader("User-Agent") String userAgent){return "User-Agent: "+userAgent;}