【问题标题】:Imitate 'gzip' content encoding on byte array在字节数组上模仿“gzip”内容编码
【发布时间】:2018-08-07 08:47:42
【问题描述】:

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

现在我无法以与尝试通过 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 拒绝)
  • 使用不同的输入流/输出流来读取数据
  • gzdecompress / gzdecode 在 PHP 端(在 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 服务器从本地存储中提供时,它将无法工作。

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2018-02-27
      • 2015-01-17
      • 1970-01-01
      • 2019-05-25
      • 1970-01-01
      • 2014-03-19
      • 2017-03-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多