我正在开发一个应用程序,它使用从服务器发送到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,这会很奇怪。)
到目前为止,我所尝试的内容如下:
我在修改后的Mapbox GL JS环境中使用axios检索磁贴,直接从服务器加载磁贴工作并完美地绘制地图数据。但是,当它通过http服务器从本地存储服务时,它将无法正常工作。
答案 0 :(得分:0)
问题是文件在输出时附加了6个字节,导致Gzip标头被隐藏。之后,使用gzip编码返回工作完美。