English 中文(简体)
ajax 随附电机发出的要求没有发挥作用
原标题:ajax send request with encoding gzip is not working

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);
}
最佳回答

问题似乎与头盔有关,但与压缩有关。

你似乎不肯压缩你的职位。 数据。

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

如果不是,让浏览器与服务器谈判转让编码(这是议定书的一部分,自动进行),服务器如果接受,则表示很少情况),或者(如果你真的需要的话)编码。 这一SO问题表明,有一个图书馆压缩浏览器:。 Javacast implementation of Gzip

问题回答

考虑到安全,浏览器不允许你凌驾于某些头盔,包括“自动编码”。

透明地要求你的XMLHttpRequest受到高度压缩的一个办法是使用HTTP/2(例如通过云层为你的网站服务)。

在使用《吉大港山区行动计划》时,尽管《吉大港山区行动计划》的负责人没有说到<条码>:gzip,但根基的《吉大港山区议定书》压缩了一切。

这还比高一些,因为:

  • it compresses headers
  • header compression uses a standard dictionary
  • I think data compression builds a dictionary over multiple messages (brotli - I haven t double-checked that though)

  1. Open Chrome, and F12 to open developer tools
  2. Click on the network tab
  3. close the request inspector panel (has tabs Headers Preview Response Timing)
  4. Right click on the Name header of the list of requests and tick Protocol
  5. Navigate to your website and watch what protocol is used for all requests - in the protocol column you want to see h2 not http/1.1

Example log of HTTP/2 network requests withn Chrome developer tools

I wouldn t recommend using JavaScript compression libraries because that causes slowdown and inefficiencies.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签