我该如何进行 HTTP GET 请求并传递 JSON 对象?
这是我的 JSON 对象。
这是我的 JSON 对象。
{{firstname:"Peter", lastname:"Test"}
我希望把这个对象作为HTTP请求参数传递,以便获取匹配的人员列表。
怎么实现呢?这个例子只展示了一个返回JSON结果的简单GET请求。我需要如何修改它呢?
//Component:
person:Person;
persons:Person [];
....
//Whre can I pass the person, here in the service??
getMatchedPersons(){
this.httpService.getMatchedPersons().subscribe(
data => this.persons = data,
error => aller(error)
);
);
//SERVICE
//pass parameters?? how to send the person object here?
getMatchedPersons(){
return this.http.get('url').map(res => res.json());
}
http.post
,要么将参数传递到查询字符串中http.get('url?firstname=$1&lastname=$2')
。 - Arg0n