ajax请求(asynchronized)与普通请求(synchronized)的报文头(Header)不同:
StringreqType=request.getHeader("X-Requested-With"); if(null==reqType){//normalrequest} elseif(reqType.equals("XMLHttpRequest")){//ajaxrequest}
1、request headers
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip,deflate,sdch
Accept-Language:zh-CN,zh;q=0.8,en;q=0.6
Connection:keep-alive
Cookie:BD_HOME=0; BD_UPN=12314353; BAIDUID=6D80EC15FB3F7D55F6CF21531B4789A2:FG=1
Host:www.baidu.com
Referer:http://news.baidu.com/
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/47.0.2526.106 Safari/537.36
response headers
BDPAGETYPE:1
BDQID:0xcc5e27ca0001088a
BDUSERID:0
Cache-Control:private
Connection:keep-alive
Content-Encoding:gzip
Content-Type:text/html; charset=utf-8
Cxy_all:baidu+1e0afc7905a9c9dcea7d6f252627f95b
Date:Fri,06 May 2016 06:35:43 GMT
Expires:Fri,06 May 2016 06:35:22 GMT
Server:bfe/1.0.8.14
Set-Cookie:PSTM=1462516543; expires=Thu,31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
Set-Cookie:__bsi=17208040824016918998_00_2870_R_N_6_0303_C02F_N_I_I_0; expires=Fri,06-May-16 06:35:48 GMT; domain=www.baidu.com; path=/
Set-Cookie:H_PS_PSSID=1442_19713_18281_19805_19899_19559_19807_19843_19902_19861_17001_15263_12288; path=/; domain=.baidu.com
Set-Cookie:BIDUPSID=6D80EC15FB3F7D55F6CF21531B4789A2; expires=Thu,31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
Set-Cookie:BD_HOME=0; path=/
Set-Cookie:BDSVRTM=0; path=/
Transfer-Encoding:chunked
Vary:Accept-Encoding
X-Powered-By:HPHP
X-UA-Compatible:IE=Edge,chrome=1
2、Ajax异步request headers
Accept:text/javascript,application/javascript,application/ecmascript,application/x-ecmascript,*/*; q=0.01
Accept-Encoding:gzip,en;q=0.6
Connection:keep-alive
Cookie:BAIDUID=6D80EC15FB3F7D55F6CF21531B4789A2:FG=1; PSTM=1462516543; BD_HOME=0; H_PS_PSSID=1442_19713_18281_19805_19899_19559_19807_19843_19902_19861_17001_15263_12288; __bsi=17208040824016918998_00_2870_R_N_6_0303_C02F_N_I_I_0; BIDUPSID=5081A970DD87C74CFFBADF0B28A1AF39; BD_UPN=12314353
Host:www.baidu.com
Referer:https://www.baidu.com/
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/47.0.2526.106 Safari/537.36
X-Requested-With:XMLHttpRequest
Ajax异步response headers
Cache-Control:private
Connection:keep-alive
Content-Length:95
Content-Type:baiduApp/json; v6.27.2.14; charset=UTF-8
Date:Fri,06 May 2016 06:35:45 GMT
Expires:Fri,06 May 2016 07:35:45 GMT
Server:bfe/1.0.8.14
Set-Cookie:__bsi=16943568347195085118_00_0_I_R_1_0303_C02F_N_I_I_0; expires=Fri,06-May-16 06:35:50 GMT; domain=www.baidu.com; path=/