我试图发出一个POST请求,但我无法让它工作:
testRequest() {
var body = 'username=myusername?password=mypassword';
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
this.http
.post('/api',
body, {
headers: headers
})
.subscribe(data => {
alert('ok');
}, error => {
console.log(JSON.stringify(error.json()));
});
}
我基本上想复制这个http请求(不是ajax),就像它是由html表单发起的一样:
URL:/api
参数:用户名和密码