HttpServletRequest获取接口请求路劲等相关方法

例如接口请求地址:http://192.168.1.6:8080/api/category/query?pageSize=5&pageNum=1
 

System.out.println(request.getRequestURL().toString());  //http://192.168.1.6:8080/api/category/query
System.out.println(request.getRequestURI()); // /api/category/query
System.out.println(request.getContextPath());// /api
System.out.println(request.getQueryString()); // pageSize=5&pageNum=1
System.out.println(request.getServletPath());// /category/query
System.out.println(request.getRemoteAddr());// 192.168.1.6
System.out.println(request.getServerPort());// 8080

//getHeader(string name)方法:根据header参数名称获取值 ;
//getParameter(name)方法:根据请求参数的名称获取对应的值;
//getMethod()方法:HTTP请求的的方法名,默认是GET,也可以指定PUT或POST;

 

你可能感兴趣的:(java,springboot)