How to send post request with only 1 argument in Angular?

2928 views angular

I'm using Angular6, HttpClient, this is logout

  logout() {

And the error is

Expected 2-3 arguments, but got 1.

It's expecting the header or data, but I don't have any data to post, if I add a header, the error is fixed, and everything will work but I don't want to do that, since I have angular HTTP interceptor, and the job of the interceptor is to add a header to any request automatically. So no need to write the same code twice.

So how to send post request with only one argument?

answered question

Stupid question: is it possible to provide an empty Header as workaround?

Just pass null to the other two arguments

@kboul null works, could you please post it as an answer just so I could close the question

Keep in mind you need to subscribe

@Oram Good point thank you for remind me.

What kind of POST request is it when you don't need body at all?

@LazarLjubenovi? if I send a post request with the header that contains the x-session I can logout, and the x-session is added automatically to the header by angular http interceptor, I don't need to write it again in logout method

1 Answer


You can simply pass null to the other arguments like this:

logout() {
   return, null, null);

posted this

Have an answer?


Please login first before posting an answer.