这篇文章将为大家详细讲解有关ajax request和normal request有哪些区别,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
ajax请求(asynchronized)与普通请求(synchronized)的报文头(Header)不同:
String reqType = request.getHeader("X-Requested-With");
if (null == reqType) {//normal request}
else if (reqType.equals("XMLHttpRequest")) {//ajax request}
1、request headers
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,p_w_picpath/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, deflate, sdch
Accept-Language:zh-CN,zh;q=0.8,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=/
关于“ajax request和normal request有哪些区别”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。