let headers = new Headers();
headers.append('Content-Type', 'application/json');
let myReq = { FirstName: "AB", LastName: "CD"}
let options = new RequestOptions({ headers: headers });
const url = 'http://myurl.com';
return this.http.post(url, options)
.map(res => res.json());
如何在此帖子请求中注入json请求(
myReq
变量)作为此帖子请求的一部分。
答案 0 :(得分:1)
尝试以下代码:
addBook() {
let books = [
{ id: 1, name: 'Core Java' },
{ id: 2, name: 'Angular 2' },
{ id: 3, name: 'Hibernate' }
];
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.post(this.url, book, options)
.map(this.extractData)
.catch(this.handleErrorObservable);
}