【发布时间】:2017-04-27 16:55:37
【问题描述】:
我正在尝试使用 angular 2 进行 http.post 调用。我已经在邮递员中测试了调用,所以我知道 api 正在工作。我收到一个错误,输入为空,这意味着它没有获取数据。我已经阅读了一些答案和文章,但无法使用数据成功调用。
谁能告诉我我所缺少的东西?
public upload(name: string, data: any, result, contentType: string) : Promise<Response> {
let headers = new Headers({ 'Content-Type': contentType });
let options = new RequestOptions({ headers: headers });
return this.http
.post(this.urlAPI, data, options)
.toPromise()
.then(this.extractData)
.catch(this.handleError);
}
extractData(res:Response) {
console.log('res: ', res);
let body = res.json();
return Promise.resolve(res);
}
handleError(err: any): Promise<any> {
console.error('An Error has occured: ', err);
return Promise.reject(err);
}
【问题讨论】:
标签: angular2-http