XMLHttpRequest对象中与标头有关的方法:

setRequestHeader(<header>,<value>)——用指定值设置标头。

getResponseHeader(<header>)——获取指定标头的值;

getAllResponseHeaders()——以单个字符串形式获取全部标头。

覆盖请求的HTTP方法,例如以下代码:可规避防火墙仅仅同意GET和POST请求通过的限制;

httpRequest.setRequestHeader("X-HTTP-Method-Override","DELETE");

禁用内容缓存:

httpRequest.setRequestHeader("Cache-Control","no-cache");
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>上海远地资产管理有限公司</title>
<meta name="author" content="jason"/>
<meta name="description" content="上海远地资产管理有限公司(简称:远地资产),是一家专业的互联网金融服务平台."/>
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon"/>
<style type="text/css">
#allheaders,#ctheader{
border: medium solid black;
padding: 2px;
margin: 2px;
}
</style>
</head>
<body>
<div>
<button>Apples</button>
<button>Cherries</button>
<button>Bananas</button>
</div>
<div id="ctheader"></div>
<div id="allheaders"></div>
<div id="target">
载入内容
</div> </table>
<script>
var buttons=document.getElementsByTagName("button");
for(var i=0;i<buttons.length;i++){
buttons[i].onclick=handleButtonPress;
}
var httpRequest;
function handleButtonPress(e){
httpRequest=new XMLHttpRequest();
httpRequest.onreadystatechange=handleResponse;
httpRequest.open("GET", e.target.innerHTML+".html");
//规避防火墙的限制,使用X-HTTP-Method-Override标头来指定想要的HTTP方法,但形式上市再发送一个POST请求
//httpRequest.setRequestHeader("X-HTTP-Method-Override","DELETE");
//禁用内容缓存
//httpRequest.setRequestHeader("Cache-Control","no-cache");
httpRequest.send();
}
function handleResponse(){
if(httpRequest.readyState==2){
document.getElementById("allheaders").innerHTML=httpRequest.getAllResponseHeaders();
document.getElementById("ctheader").innerHTML=httpRequest.getResponseHeader("Content-Type");
}else if(httpRequest.readyState==4 && httpRequest.status==200){
document.getElementById("target").innerHTML= httpRequest.responseText;
}
} </script><pre name="code" class="html"></body>
</html>

最新文章

  1. JavaScript小细节点罗列
  2. 【BZOJ2157】旅游 LCT
  3. APP弱网测试
  4. “FAIL - Deployed application at context path but context failed to start”错误的解决
  5. Xamarin.Android提示aapt退出,代码为255
  6. 将 Web 应用性能提高十倍的10条建议
  7. Android系统进程间通信Binder机制在应用程序框架层的Java接口源代码分析
  8. virus.win32.parite.H病毒的查杀方法
  9. 关于查看文件size
  10. python rsa 加密解密 (编解码,base64编解码)
  11. HTTP多线程下载+断点续传(libcurl库)
  12. shell脚本获取进程ID并杀死的实现及问题解析
  13. js 获取 时间戳的三种方法
  14. #WEB安全基础 : HTML/CSS | 0x6嵌套标签(图片链接)
  15. Linux(Ubuntu 16) 下Java开发环境的配置(一)------JDK的配置
  16. 使用Autoencoder进行降维
  17. nginx出现404和403错误
  18. 压缩软件WinRar 5.5 x64去广告方式【窗口类名下断】
  19. Scrapy基础(四)————Scrapy的使用Pycharm进行Debuge设置
  20. teamview修改id

热门文章

  1. Python全栈开发第二期课表
  2. BIT+DP
  3. [错误处理]: How to deal with chrome failing to launch GPU process
  4. API生命周期第二阶段——设计:如何设计API(基于swagger进行说明)
  5. 关于php ‘==’ 与 &#39;===&#39; 遇见的坑
  6. iptables之ipset集群工具
  7. NOJ——1624死胡同(胡搞模拟)
  8. 如何在 Windows 上 使用 ONLYOFFICE 协作编辑文档
  9. npm scripts设置环境变量方法
  10. d3 画简单的柱形图