gpt4 book ai didi

Angular 6 : How to get response status code

转载 作者:行者123 更新时间:2023-12-04 22:07:19 24 4
gpt4 key购买 nike

如何获取服务代码?我尝试下面的代码,但它没有记录任何内容。

在 service.ts 文件中。

constructor(private http: HttpClient) { }

postForgotPass(email): Observable<Response> {

return this.http.post<Response>(envi.apiUrl +'/user/forgotpassword', {
"email": email,
"headers": headers,
observe: 'response'

})
}

在我的 component.ts 文件中
sendForgotPass() {
return this.service.postForgotPass(this.emailFormControl.value)
.subscribe(
res => {
console.log(res.status);
})
}

最佳答案

来自 Angular docs :

getConfigResponse(): Observable<HttpResponse<Config>> {
return this.http.get<Config>(
this.configUrl, { observe: 'response' });
}

用法
this.configService.getConfigResponse()
// resp is of type `HttpResponse<Config>`
.subscribe(resp => {
// display its headers
const keys = resp.headers.keys();
this.headers = keys.map(key =>
`${key}: ${resp.headers.get(key)}`);

// access the body directly, which is typed as `Config`.
this.config = { ... resp.body };
});

关于 Angular 6 : How to get response status code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55247103/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com