Http请求头中X-Requested-With的含义

时间:2025-04-12 08:12:22

昨天看代码的时候,看到了这个一句

String requestedWith = ((HttpServletRequest) request).getHeader("X-Requested-With");

X-Requested-With看到这个玩意并不知道是啥

于是查了一下

if (("x-requested-with") != null
    && ("x-requested-with").equalsIgnoreCase("XMLHttpRequest")) {
    ("该请求是AJAX异步HTTP请求。");
} else {
    ("该请求时传统的同步HTTP请求。");
}

  如果requestedWith为null,则为同步请求。

  如果requestedWith为XMLHttpRequest则为Ajax请求。


1、X-Requested-With这个Http请求头有什么作用?

/question/30795602

2、HTTP之X-Requested-With分析和思考

/javajiawei/article/details/50563154

3、Ajax之X-Requested-With请求头 

http://blog./woshixy/976695

4、Ajax 请求的http头信息特点 x-requested-with 

/blog/2316105

 

转自:/heatdeath/article/details/79168614