繁体   English   中英

如何在 Angular 中向 HTTP GET 请求添加正文

[英]How to add body to the HTTP GET request in Angular

我正在尝试将正文添加到 HTTP GET 请求中。 但无法添加

我尝试过 RequestOptions 但它没有用。

对于上述代码,POST 请求有效但 GET 无效

getlist(name : string) : Observable<Object[]> {

var body = {
  "listname" : name
}

 return this.http.post<any>("http:/regsd.com/api/lists/",body)
}

您可以在 GET 请求中传递查询参数。

getlist(name : string) : Observable<Object[]> {
  return this.http.get<any>(`http:/regsd.com/api/lists/?listname=${name}`);
}

正文只能在 POST 和其他动词(如 HTTP 中的 PUT)中设置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM