我在角色2帖子请求上有点挣扎,这让我觉得很愚蠢:P我似乎无法将数据/正文拉到Express / Node。以下是我的角度:
import { Injectable } from '@angular/core';
import { Http, Headers, RequestOptions } from '@angular/http';
import 'rxjs/add/operator/map';
@Injectable()
export class Signup {
constructor(private http: Http) {}
submitForm(data: Object) {
let url = 'http://localhost:8022/api/signup';
let body = JSON.stringify({ 'foo': 'bar' });
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.post(url, body, options)
.map(res => res.json().data)
}
}
在快递中我试试这个:
router.post('/api/signup', (req,res,next) => {
console.log('content-type', req.headers['content-type'])
console.log('req.body', req.body)
res.status(200).json({message: "user created!"})
})
但正如你在我的控制台中看到的那样,没有任何机构可以通过:
content-type application/json
req.body undefined
任何人都知道我做错了什么?