编码为gzip的ajax发送请求不起作用 [英] ajax send request with encoding gzip is not working

查看:91
本文介绍了编码为gzip的ajax发送请求不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编码为gzip(iis7)的Ajax发送请求无法正常工作,下面是发送请求的代码有人可以帮我解决我代码中的错误吗?

Ajax send request with encoding gzip (iis7) is not working below are the code for send request can some one help me what is wrong in my code.

预先感谢

function sendRequest(url, callback, postData)
{
   var req = createXMLHTTPObject();
   if (!req) {
      return;
   }

   var method = (postData) ? "POST" : "GET";
   req.open(method, "xml/" + url, true);
   req.setRequestHeader('User-Agent', 'XMLHTTP/1.0');

   if (postData) {
      req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
      req.setRequestHeader("Content-Encoding", "gzip");

   }

   req.onreadystatechange = function() {

   }

   req.send(postData);
}

推荐答案

问题似乎与标题无关,而与压缩有关.

The problem doesn't seem to be related to header but to compression.

您似乎没有压缩postData.

You don't seem to compress your postData.

如果postData已被压缩,则无需尝试手动设置内容编码.

If postData is already compressed, no need to try to manually set content-encoding.

如果不是,请让浏览器与服务器协商传输编码(这是协议的一部分并自动完成,服务器会说是否接受),或者(如果您同意,确实需要对它自己进行编码.这个SO问题指示一个用于压缩浏览器端的库: Gzip的JavaScript实现

If it is not, either let the browser negotiate the transfer encoding with the server (this is part of the protocol and done automatically, the server saying if it accepts it, but I think that's rarely the case) or (if you really really need to) encode it yourself. This SO question indicates a library to compress browserside : JavaScript implementation of Gzip

这篇关于编码为gzip的ajax发送请求不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆