Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 6 - HTTP Response 200 is null in subscribe [duplicate]

I have the following Angular http.service.ts which I use to call the /login API.

login(user: User) {
    console.log("logging in");
    console.log(JSON.stringify(user));
    this.http
        .post<any>(this.loginURL, user, httpOptions)
        .subscribe(
            res => console.log('response : ' + res),
            err => console.log('error : ' + err))
}

This is a really standard POST call but it always returns null and I can't get why. This is the Network Google Chrome's tab information

enter image description here

The Chrome's Console information

enter image description here

I can't get why the response is null. Even though I have no payload, it should at least make the headers available no?

like image 729
Yassin Hajaj Avatar asked Jun 09 '18 23:06

Yassin Hajaj


1 Answers

Try the following:

this.http.post("url", body, {headers: headers, observe: "response"})
   .subscribe(res => console.log(res));

You can take the same http options you have but add the observe: response. the header is HttpHeaders from http client. ex: headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded'),

like image 123
Nour Avatar answered Nov 10 '22 18:11

Nour