在此处遵循教程Listening to Progress Events
我想问问response
进行之后是否可以从服务器返回HttpEvent
?
这是我的示例代码。
const req = new HttpRequest('POST', url, formData, {
reportProgress: true,
responseType: 'json',
});
getEventMessage(event: HttpEvent<any>) {
switch (event.type) {
case HttpEventType.Sent:
return 'Uploading data...'
case HttpEventType.UploadProgress:
const percentDone = Math.round(100 * event.loaded / event.total)
return `is ${percentDone} uploaded.`
case HttpEventType.Response:
return `was completely uploaded. ` + event.body; // I want to show the json response from server.
//return HttpEventType.Response;
default:
// code...
return `surprising upload event: ${event.type}.`;
}
}
this.http.request(req).pipe(
map(event => console.log(this.getEventMessage(event))),
tap(message => console.log('Message: '+ message)), // message undefined
last(),
).subscribe(response => {
console.log('RESPONSE: ', response); // It returns undefined
})
我想显示来自服务器的json
响应。说真的,我对如何做一无所知。任何帮助表示赞赏。
谢谢!