我的问题是来自 Angular 4 的 HttpClient 对服务器的多个请求。简单的测试代码:
import {Component} from '@angular/core';
import {HttpClient} from '@angular/common/http';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app';
constructor(private http: HttpClient) {
}
startTest(): void {
this.http.get('/dictionary/1.0/dictionary/pl/events', {
observe: 'body',
}).subscribe(
(data) => {
console.log('Data', data);
}
);
this.http.get('/dictionary/1.0/dictionary/pl/event_state', {
observe: 'body'
}).subscribe(
(data) => {
console.log('Data', data);
}
);
this.http.get('/dictionary/1.0/dictionary/pl/event_sentby_categories', {
observe: 'body'
}).subscribe(
(data) => {
console.log('Data', data);
}
);
}
}
结果该请求中至少有一个将成功执行,但其余请求将失败,并出现错误“JSON 解析错误:意外的 EOF”。
看起来其余服务的后续调用正在取消当前存在的(未完成的)调用。我看到了 Observable.forkJoin 的示例以并行发出请求,它们也不起作用。我试过不同的浏览器(都在Mac上),效果是一样的。