我正在尝试发出 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 表单发起的一样:
网址:/api
参数:用户名和密码
原文由 Christopher 发布,翻译遵循 CC BY-SA 4.0 许可协议
我认为正文不适合
application/x-www-form-urlencoded
内容类型。你可以尝试使用这个:希望它可以帮助你,蒂埃里