我正在使用 Angular 的新 HttpClient 来处理请求。当我使用旧的 http 时,我的组件返回正文文本很好,但现在正文文本为空。我不明白,服务器正在发送它,但我总是收到 null 作为正文。
响应的所有其他部分都是正常的,状态 200 等。放置和删除都需要纯文本成功消息。我还尝试使用 .body 方法来获取正文文本,并且也返回 null。
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' });
}
}
成分:
this.whiteListService.sendAllow(a, b)
.subscribe(
(response) => console.log(response),
(error) => {
console.log(error);
}
);
问题是 Angular 正在等待 json 响应。将响应更改为键入文本,如下所示:
return this.http.put(`http://${this.address}/rest/geodrop/config/` +
`${country}`, { responseType: 'text', observe: 'response' });
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)