Readable http body

I’d like to make the following code cleaner:

this.http.post("http://..........", 'username=' + user + '&password=' + passw, options)

I tried this code but it doesn’t work:

let body = JSON.stringify({
        username: user,
        password: passw
      });

      this.http.post("http://..........", body, options)

HttpParams.

Your code:

let body = JSON.stringify({username: user, password: passw});

returns

“{“username”:“a”,“password”:“b”}”

Thank you.
I tried this code, but it doesn’t work:

let httpParams = new HttpParams().set('username', 'John').set('password', '123456');
this.http.post("http://..........", httpParams, options)

The HttpParams object goes in as part of the options. See an example here.

Solved:

let params = new URLSearchParams()
params.append('username', 'John');
params.append('password', '123456');
this.http.post("http://..........", params.toString(), options)

@Pasto92 Thanks @Pasto92, it will help me solve some code of mine :slight_smile: Have fun with Ionic :slight_smile: