0
我试图做一个Web应用程序,我想测试HTTP功能,但我有一个问题。角4:HTTP不发送POST数据
例如:我有这样的:
import { Injectable } from '@angular/core';
import { Headers, RequestOptions, Http } from '@angular/http';
import {Observable} from 'rxjs/Rx';
// Import RxJs required methods
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
@Injectable()
export class UserService {
constructor(private http: Http) { }
create(data: Object): Observable<any> {
let headers = new Headers({'Content-Type': 'application/x-www-form-urlencoded'}),
options = new RequestOptions({ headers: headers});
return this.http.post('http://localhost:8000/api/signin', {headers:headers}).map((res) => { res.json(); alert('ma-ta'); }).catch((error:any) => Observable.throw(error.message));
}
}
的函数被调用,我核实,但http.post不工作,我的意思是,它不是将数据发送到该链接,在控制台我什么都没有的网络,我收到此:
12:01:18.779 Object { _isScalar: false, source: Object, operator: Object } 1 main.bundle.js:444:9
这是一个有点空,唯一的东西我不需要,这样的错误信息或东西。 有人能帮助我吗?
它是一样的,也许我进口的东西错了吗?我使用'@ angular/http'中的import {HttpModule}; –
是你的API期望的应用程序/ json的内容类型?你确定你的“数据”正在通过吗?你确定你的API期待与'data'相同的模型吗? –
它在Laravel中的API并期望发布数据,无论如何,我应该在Inspect Element - > Network中查看POST方法 –