Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何发布ajax响应?_Javascript_Ajax_Browser_Http Headers_Gzip - Fatal编程技术网

Javascript 如何发布ajax响应?

Javascript 如何发布ajax响应?,javascript,ajax,browser,http-headers,gzip,Javascript,Ajax,Browser,Http Headers,Gzip,我正在尝试压缩ajax请求的JSON响应内容。服务器是用C编写的非常基本的http服务器 浏览器能够将请求中所需的内容编码标题发送到服务器 请求标头如下所示: Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding:gzip,deflate,sdch Content-Type:application/x-www-form-urlencoded Origin:http://127.

我正在尝试压缩ajax请求的JSON响应内容。服务器是用C编写的非常基本的http服务器

浏览器能够将请求中所需的
内容编码
标题发送到服务器

请求标头如下所示:

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding:gzip,deflate,sdch
Content-Type:application/x-www-form-urlencoded
Origin:http://127.0.0.1:1234
Referer:http://127.0.0.1:1234/index.html
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36
X-Requested-With:XMLHttpRequest
因为,我的服务器可以看到有可用的
Accept-Encoding:gzip、deflate、sdch
方法,它将deflate设置为
gzip
,并将响应头设置为

Content-Encoding:gzip
只有这些信息

Cache-Control:no-cache
charset:UTF8
Content-Length:134
Content-Type:text/plain
Expires:0
Pragma:no-cache
(注意:它包括
内容编码:gzip

完成所有这些操作后,浏览器会在该请求的“网络”选项卡中显示“失败”

同样的压缩也适用于
GET
请求

  • 我不能为
    POST
    响应放气吗?如果是,我是怎样做的 这里不见了?
  • 还有其他选择吗?

  • 谢谢

    你的问题有点不清楚。您正在尝试用C编写自己的http服务器吗?我怀疑服务器返回的内容没有正确的gzip编码。您可以使用Fiddler来确定这一点。请参阅我在此处发布的关于如何做到这一点的帖子: