【发布时间】:2021-01-24 03:10:50
【问题描述】:
这就是我在 Postman 中将参数传递给我的 http post 请求的方式。它的状态是好的 200。
我正在尝试从这样的角度代码中做到这一点。
getInfo() {
const params = [];
params.push({code: 'checkinFrom', name: '2019-02-01'});
params.push({code: 'checkinTo', name: '2019-10-01'});
params.push({code: 'room_type_ids', name: [2]});
console.log(params);
return this.service.post(environment.url + 'v1/transactions/demand/price-info', params);
}
这是我在 Service 类中的 post 方法。
post(path, body): Observable<any> {
return this.http
.post(
path,
body,
{
headers: Service.setHeaders([])
}
)
.pipe(
catchError(error => {
throw error;
}),
map((res: Response) => res)
);
}
但是在 Angular 前端,当我尝试发送参数时,它会给出类似 422 (Unprocessable Entity) 的错误。我想如何传递参数?
【问题讨论】:
标签: angular rest http-post url-parameters query-parameters