如何在 Angular 中仅发送 1 个参数的 post 请求?
How to send post request with only 1 argument in Angular?
我用的是Angular6,HttpClient,这是注销
logout() {
return this.http.post(this.logout_url);
}
错误是
Expected 2-3 arguments, but got 1.
需要 header 或数据,但我没有 post 的任何数据,如果我添加 header,错误已修复,一切正常但我不想这样做,因为我有 angular HTTP 拦截器,拦截器的工作是自动向任何请求添加 header。因此无需将相同的代码写两次。
那么如何只发送一个参数的post请求呢?
您可以像这样简单地将 null
传递给其他参数:
logout() {
return this.http.post(this.logout_url, null, null);
}
我用的是Angular6,HttpClient,这是注销
logout() {
return this.http.post(this.logout_url);
}
错误是
Expected 2-3 arguments, but got 1.
需要 header 或数据,但我没有 post 的任何数据,如果我添加 header,错误已修复,一切正常但我不想这样做,因为我有 angular HTTP 拦截器,拦截器的工作是自动向任何请求添加 header。因此无需将相同的代码写两次。
那么如何只发送一个参数的post请求呢?
您可以像这样简单地将 null
传递给其他参数:
logout() {
return this.http.post(this.logout_url, null, null);
}