场景:构造一个返回请求参数(表单入参),请求header,设置响应header的测试demo接口
框架:springboot
@ResponseBody
@RequestMapping("/test/api/v1")
public Map serverPostTestv1(HttpServletRequest httpRequest, HttpServletResponse httpResponse,@RequestHeader MultiValueMap<String,String> reqHeaders){
Map map = new HashMap();
Map reqheadersmap = new HashMap();
Map reqparamsmap = new HashMap();
LOG.info("请求headers是:"+ reqHeaders);
//获取请求header
reqheadersmap.put("reqheaders",reqHeaders);
//获取请求参数
Enumeration paramNames = httpRequest.getParameterNames();
while(paramNames.hasMoreElements()){
String paramName = (String) paramNames.nextElement();
String[] paramValues = httpRequest.getParameterValues(paramName);
LOG.info("请求params是:"+ paramName);
if(paramValues.length >0){
String paramValue = paramValues[0];
if(paramValue.length() != 0){
LOG.info("reqparamsmap.put 是:"+ paramName+","+paramValue);
reqparamsmap.put(paramName,paramValue);
}
}
}
//设置响应headers
httpResponse.setHeaders("Content-Finished","999");
httpResponse.setHeaders("Content-Halo","togwtest");
//请求头,请求参数放进map
map.put("reqparams",reqparamsmap);
map.put("reqheaders",reqheadersmap);
return map;
}
标签:map,网关,场景,请求,Map,接口,reqparamsmap,paramName,put From: https://www.cnblogs.com/yinzone/p/17642166.html