gpt4 book ai didi

javascript - 服务器响应中的 Angular 模板中未定义

转载 作者:太空宇宙 更新时间:2023-11-04 03:19:18 24 4
gpt4 key购买 nike

我有一个单用户登录系统。在整个组织和所有应用程序中,凭据都是相同的。当我从 Angular 发送登录请求时,响应低于:

"Status Code{\"statusCode\":200,\"body\":\"\",\"headers\":{\"date\":\"Thu, 13 Sep 2018 16:04:46 GMT\",\"x-powered-by\":\"Servlet/3.0\",\"content-length\":\"0\",\"set-cookie\":[\"LtpaToken2=UXVOlmR+cut/Qu/cxxxmWaEOEkCtxxxq22GgCI4Iz8nffc1n8O1l5AE0sUCPQfZ+nB9vXS/WMkzxanOexJHzJZb4IgqoxTc0UztF+1amzVysdvdBSSIoblF8fFc9iRMkjYPbxZISg29sU1Q6Au0+Dh50ARY1NhkRQ8iwVst1X6Pbc3Dn4YpLO08utqAi9+35Pun+IFJnbTF6BRvleLKXDifZzwmuZlRKs5gseb9GELQYjTLlXFykm8aq0Ulh0Z8VT/xi0uRFFiR0eUrEvo58sev/3XPYv10//ZTkWOqFnADdzhsBoW4wtWVjlFcvlB/24TBaKtNWmYJd3/tsnoRCWPn1yd4udC0YDFsr3h5SGAjgCRMg7gH8+hvpnIiKzzfcxNmQTPlRjav+SUkBfIxAQ5gmGOmDXDcuzMSbx8zJk1RGNcM/Ksmrcv+SOoDMtmCDHWWqTVn9VLPAnF9bZE7Fkmis7QcNxK5UAoMTCCzgfwMEwHeWm4fY7DblWi8RM=; Path=/\",\"JSESSIONID=0000LsRRstmAD-Y923str-8:-1; Path=/\"],\"expires\":\"Thu, 01 Dec 1994 16:00:00 GMT\",\"cache-control\":\"no-cache=\\"set-cookie, set-cookie2\\"\",\"content-language\":\"en-US\",\"connection\":\"close\"},\"request\":{\"uri\":{\"protocol\":\"http:\",\"slashes\":true,\"auth\":null,\"host\":\"abcd.com\",\"port\":80,\"hostname\":\"abcd.com\",\"hash\":null,\"search\":null,\"query\":null,\"pathname\":\"/hello/rest/login\",\"path\":\"/hello/rest/login\",\"href\":\"http://abcd.com\"},\"method\":\"GET\",\"headers\":{\"authorization\":\"Basic r8htMGw5adkhobSMzYXVn\"}}}"

当我尝试访问登录组件中的状态代码时,我得到了未定义的信息,

this.apiDataService.getLogin(user).subscribe((data: any) => {
if (data.statusCode==200) {
this.apiDataService.storeUserData(data.headers, data.authorization);
this.router.navigateByUrl('/validate');
} else {
this.loginError = true;
this.errMsg = 'Invalid username/password';
}

请建议我如何获取状态代码以及我应该使用什么来进行 session 管理,例如我无法使用的 set-cookie。 });

最佳答案

尝试使用 data.json() 将响应解析为 JSON 对象,

this.apiDataService.getLogin(user).subscribe((data: any) => {
var response=data.json();
if (response.statusCode==200) {
this.apiDataService.storeUserData(response.headers, response.authorization);
this.router.navigateByUrl('/validate');
} else {
this.loginError = true;
this.errMsg = 'Invalid username/password';
}

关于javascript - 服务器响应中的 Angular 模板中未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52328798/

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