我正在尝试发出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()));
});
}
Run Code Online (Sandbox Code Playgroud)
我基本上想要复制这个http请求(不是ajax),就像它是由html表单生成的:
网址:/ api
参数:用户名和密码