使用 Angular2 http 发送带有查询参数的 GET 请求时,发送的参数没有按我的预期发送。而不是标准的键值对,例如
key1=val1&key2=val2
它作为 HttpParams 对象发送,例如
%7B%22param%22:%key1%22,%22value%22:%22val1%22,%22op%22:%22a%22%7D
*解码:
{"param":"key1","value":"val1","op":"a"}
下面是我的代码片段:
getAllPlayers(fantasyFormat: string, draftFormat: string): Observable<Player[]> {
let params = new HttpParams();
params = params.append('fantasyFormat', fantasyFormat);
params = params.append('draftFormat', draftFormat);
return this.http.get(this.playersUrl, {params: params})
.map((res: Response) => res.json())
.catch((error: any) => Observable.throw(error.json().error || 'Server error'));
}
不确定这里出了什么问题,似乎与我遵循的其他示例一致......