我正在尝试使用以下方法发出请求:
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});
请求通过但不发送参数任何人都可以告诉我我做错了什么?
答案 0 :(得分:2)
您必须使用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});
答案 1 :(得分:0)
尝试这样的事情,认为params是额外的,并且在处理请求时不是标题的一部分。
let ht = new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': 'my-auth-token',
});
let p = {where:{id: 1}};
return this.http.get(environment.apiUrl + route, {headers: ht, params: p});