我目前从Angular开始。我们正在与我的团队一起准备一些POC,以在我们的应用程序中交换视图。长话短说-我们正在使用其他团队的模块以及所有发送响应的机制,依此类推,因此我们在后端的工作只是创建端点,获取数据并从“其他团队的模块”中调用适当的方法。上一次,他们将内容编码从“ UTF-8”更改为“ gzip,deflate”,并且自此之后,我们的Angular rest调用停止了工作。发送到后端的每个请求均以:
net::ERR_CONTENT_DECODING_FAILED 200 (OK)
HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "Unknown Error"
我将此后端REST模块改回为发送编码为“ UTF-8”的响应,并且一切恢复正常。
最近几天我到处看起来都很像,但丝毫没有发现。这是一些代码:
呼叫端点:
private loadResulst() {
const URL = '/results/v1';
this.apiService.getResource(URL).subscribe(data => {
let newValues = [{id: 0, name:''}]
data['resultList'].forEach((value: string, index: number) => {
newValues.push({ id: index + 1, name: value });
})
this.results = newValues;
});
}
apiService.getResource:
getResource(resourceUrl: string): Observable<Object> {
const httpOptions = { headers: this.headers };
return this.httpClient.get(this.apiUrl + resourceUrl, httpOptions);
}
请求标头:
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,pl;q=0.8
Connection: keep-alive
Host: localhost:4200
Referer: http://localhost:4200/
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36
响应标题:
Access-Control-Allow-Origin: *
connection: close
content-encoding: deflate, gzip
content-length: 69
content-type: application/json
date: Fri, 21 Feb 2020 07:59:11 GMT
server: Apache-Coyote/1.1
X-Powered-By: Express
x-ua-compatible: IE=9
当通过具有相同标题的Postman处理数据时,我得到的数据没有任何问题。
发现。根据this SO topic,“当HTTP请求的标头声称内容是gzip编码的,但是不是,则发生。”