Wil*_*ire 11 http typescript angular-http angular
我想知道如何在没有正文的情况下发送HTTP post请求(特别是在Angular中).这就是我现在正在做的事情,但我收到了错误Expected 2-3 arguments, but got 1).
我意识到第二个参数是针对正文的,但我并没有将它发送到服务器(是的,我知道POST调用改变了系统的状态并且已经查看了这个问题).
postRequest(id) {
this.http.post('/api?data=' + id).map(
(response) => {
return response;
}
)
}
Run Code Online (Sandbox Code Playgroud)
Wil*_*ire 17
看起来这是一个合适的答案:
postRequest(id) {
this.http.post('/api?data=' + id, null).map(
(response) => {
return response;
}
)
}
Run Code Online (Sandbox Code Playgroud)
如果null不起作用(4XX 错误客户端),请尝试使用{}JSON:
postRequest(id) {
this.http.post('/api?data=' + id, {}).map((response) => {return response;});
}
Run Code Online (Sandbox Code Playgroud)