我正在使用Angular的新HttpClient进行请求。当我使用旧版本http时,我的组件可以正常返回文本内容,但现在文本内容为null。我无法弄清楚问题所在,服务器确实已经发送了响应,但我一直收到null作为响应体。
响应的其他部分都是正常的,如状态码200等。put和delete都需要纯文本的成功消息。我还尝试使用.body方法获取响应体文本,但也返回null。
服务:
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' });
}
}
组件:
this.whiteListService.sendAllow(a, b)
.subscribe(
(response) => console.log(response),
(error) => {
console.log(error);
}
);