我有NativeScript和Angular混合应用程序。 在NativeScript版本中,某些请求返回错误,某些可以正常工作。 在Web项目上,所有请求都可以正常工作。 如何解决此请求,使其在移动应用上正常运行?
我尝试通过HttpClient和fetch发出请求,两种方法均失败。
获取方法:
get() {
fetch(this.url + '/data', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
}).then((r) => r.json())
.then((response) => {
console.log('res', response);
}).catch((e) => {
console.log('err', e);
});
}
获取错误:
TypeError: Network request failed: java.io.EOFException: Unexpected end of ZLIB input stream
HttpClient方法:
constructor(
private http: HttpClient,
) {}
get(): Observable<any> {
return this.http.get<any>(this.url + '/data',);
}
HttpClient错误:
"headers": {
"normalizedNames": {},
"lazyUpdate": null,
"headers": {}
},
"status": 0,
"statusText": "Unknown Error",
"url": null,
"ok": false,
"name": "HttpErrorResponse",
"message": "Http failure response for (unknown url): 0 Unknown Error",
"error": {
"originalStack": "Error: java.io.EOFException: Unexpected end of ZLIB input stream\n at new ZoneAwareError (file:///data/data/org.nativescript.ngsample/files/app/vendor.170597:33)\n at onRequestComplete
(file:///data/data/org.nativescript.ngsample/files/app/vendor.190367:34)\n at Object.onComplete (file:///data/data/org.nativescript.ngsample/files/app/vendor.190356:13)",
"zoneAwareStack": "Error: java.io.EOFException: Unexpected end of ZLIB input stream\n at onRequestComplete (file:///data/data/org.nativescript.ngsample/files/app/vendor.190367:34) [<root>]\n at Object.onComplete (file:///data/data/org.nativescript.ngsample/files/app/vendor.190356:13) [<root>]"
}
}