Response body is null, status 200

I am using Angular's new HttpClient for queries. When I used the old http, my component returned the body text completely, but now the body text is null. I can't figure it out, the server sends it, but I always get null as a body.

all other parts of the answer are normal, status 200, etc. Both put and delete expect messages about successful text. I also tried using the .body method to get the main text, and it also returns zero.

service:

constructor(private http: HttpClient) {}

    sendAllow(country, allow) {
        if (allow === 1) {
            return this.http.put(`http://${this.address}/rest/geodrop/config/` +
                                 `${country}`, { observe: 'response' });
        } else {
            return this.http.delete(`http://${this.address}/rest/geodrop/config/` +
                                    `${country}`, { observe: 'response' });
        }
    }

component:

this.whiteListService.sendAllow(a, b)
            .subscribe(
                (response) => console.log(response),
                (error) => {
                    console.log(error);
                }
        );
+4
source share
1 answer

Angular issue awaiting json response. change the text type response as follows:

return this.http.put(`http://${this.address}/rest/geodrop/config/` +
                     `${country}`, { responseType: 'text', observe: 'response' });
+8
source

All Articles