我正在尝试使用以下方法发出获取请求:
let ht = new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': 'my-auth-token',
'params': '{where:{id: 1}}'
});
return this.http.get(environment.apiUrl + route, {headers: ht});
请求通过但未发送参数,谁能告诉我我在做什么错?
最佳答案
您必须使用来自http的HttpParams将额外的参数发送到api调用。
import {HttpHeaders, HttpParams } from '@angular/common/http';
let ht = new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': 'my-auth-token',
});
//Create new HttpParams
let p= new HttpParams().
set("param1",p1).
set("param2", p1);
return this.http.get(environment.apiUrl + route, {headers: ht, params: p});