模仿' gzip'字节数组上的内容编码

时间:2018-02-27 16:14:12

标签: android http-headers gzip mapbox-gl-js androidasync-koush

我正在开发一个应用程序,它使用从服务器发送到Mapbox GL JS的.pbf文件,使用标题' Content-Encoding:gzip'来自PHP,我现在正试图模仿存储中瓷砖的相同行为。

现在我无法以类似的方式执行此操作,因为我尝试从android存储中传递切片,因为每当我将响应添加到响应时,它会立即拒绝以下拒绝信息:

{
"config": {
    "transformRequest": {},
    "transformResponse": {},
    "timeout": 0,
    "xsrfCookieName": "XSRF-TOKEN",
    "xsrfHeaderName": "X-XSRF-TOKEN",
    "maxContentLength": -1,
    "headers": {
        "Accept": "application/json, text/plain, */*"
    },
    "method": "get",
    "Access-Control-Allow-Origin": "*",
    "Accept": "*/*",
    "url": "http://localhost:8080/get-tile/14/8468/5344"
},
"request": {
    "statusText": "",
    "status": 0,
    "responseURL": "",
    "response": "",
    "responseType": "",
    "responseXML": null,
    "responseText": "",
    "upload": {
        "ontimeout": null,
        "onprogress": null,
        "onloadstart": null,
        "onloadend": null,
        "onload": null,
        "onerror": null,
        "onabort": null
    },
    "withCredentials": false,
    "readyState": 4,
    "timeout": 0,
    "onprogress": null,
    "onloadstart": null,
    "onloadend": null,
    "onload": null,
    "onabort": null
    }
}

当我不使用标题时;响应发送正常并显示仍然压缩的数据,Mapbox GL JS无法理解。现在,我已经尝试使用GZIPOutputStream和GZIPInputStream来读取文件并对其进行收缩以获取正确的数据,但是它一直向我显示与文件本身的标题不正确或者不存在相关的错误。一个GZIP类型(考虑使用Content-Encoding: gzip作为支持头从PHP提供相同的二进制blob,这会很奇怪。)

到目前为止,我所尝试的内容如下:

  • 添加标题(这导致请求被上面的json拒绝)
  • 使用不同的输入流/输出流来读取数据
  • PHP上的
  • gzdecompress / gzdecode(在Windows 10上的WampServer x64上运行PHP 7,这会引发数据错误)
  • 使用十六进制编辑器检查文件,以查看工作磁贴和无效压缩磁贴之间的区别Link to a drive with the files, both from the same server one with the Header on and one with it off
  • 尝试在javascript端进行gzip解压缩(这导致几乎没有任何事情发生)

我在修改后的Mapbox GL JS环境中使用axios检索磁贴,直接从服务器加载磁贴工作并完美地绘制地图数据。但是,当它通过http服务器从本地存储服务时,它将无法正常工作。

1 个答案:

答案 0 :(得分:0)

问题是文件在输出时附加了6个字节,导致Gzip标头被隐藏。之后,使用gzip编码返回工作完美。

相关问题