昨天看代码的时候,看到了这个一句
String requestedWith = ((HttpServletRequest) request).getHeader("X-Requested-With");
X-Requested-With看到这个玩意并不知道是啥
于是查了一下
if (request.getHeader("x-requested-with") != null
&& request.getHeader("x-requested-with").equalsIgnoreCase("XMLHttpRequest")) {
out.print("该请求是AJAX异步HTTP请求。");
} else {
out.print("该请求时传统的同步HTTP请求。");
}
如果requestedWith为null,则为同步请求。
如果requestedWith为XMLHttpRequest则为Ajax请求。
1、X-Requested-With这个Http请求头有什么作用?
https://www.zhihu.com/question/30795602
2、HTTP之X-Requested-With分析和思考
http://blog.csdn.net/javajiawei/article/details/50563154
3、Ajax之X-Requested-With请求头
http://blog.51cto.com/woshixy/976695
4、Ajax 请求的http头信息特点 x-requested-with
http://rd-030.iteye.com/blog/2316105
转自:https://blog.csdn.net/heatdeath/article/details/79168614
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)