目录
1、header Referer 含义和作用
Referer
是header
的一部分,当浏览器向web服务器发送请求的时候,一般会带上Referer,告诉服务器页面的请求地址,服务器就可以进行信息处理了。
- 防盗链。
我在www.google.com里有一个www.baidu.com链接,那么点击这个www.baidu.com,它的header信息里就有:
Referer=http://www.google.com ,那么可以利用这个来防止盗链了
- 请求的拦截。
后台可以设置一个Referer
白名单,只有在白名单中的域名发起请求,才给正确结果
2、http post请求 接收和发送数据
1、http post请求有两种发送数据的方式,放入request body中和通过参数的方式提交
//方式一,通过body提交
JSONObject json = new JSONObject();
json.put("user", "aaaaaaaaa");
String jj = JSON.toJSONString(json);
HttpUtil.post("http://localhost:11001/external/test", jj);
//通过map参数提交
Map<String, Object> map = MapUtil.newHashMap();
map.put("aaa", 1);
map.put("bbbb", "bbbb");
HttpUtil.post("http://localhost:11001/external/test", map);
2、http post 服务器端接收数据或者参数
方式一:从HttpServletRequest request中获取body的值,不像mvc一样可以直接@RequestBody获取
//方式一,从request body中取值
BufferedReader br = request.getReader();
String str = "";
String listString = "";
while ((str = br.readLine()) != null) {
listString += str;
}
JSONObject oj = JSON.parseObject(listString);
//方式二、接收参数
Map<String, String[]> params = request.getParameterMap();