【发布时间】:2019-06-13 00:11:56
【问题描述】:
我正在开发一个带有 spring 后端的 angular 7 web 应用程序,我实现了安全性,所以当你使用正确的凭据登录时 spring 会给出一个 JSESSIONID cookie。如果我尝试使用邮递员登录,我会收到 cookie,一切正常,但从角度来看,即使服务器以 200 响应,它似乎也没有收到 cookie。
我的 login.service.ts:
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class LoginService {
private apiURL = 'http://127.0.0.1:8080';
constructor(
private http: HttpClient
) { }
login(credentials) {
let params = new HttpParams()
.set('username', credentials['username'])
.set('password', credentials['password'])
return this.http.post<any>(`${this.apiURL}/login`, credentials, {
'headers': {
'Content-Type': 'application/x-www-form-urlencoded'
},
'params': params
})
}
}
我在 login.component.ts 中的登录方法:
login(){
this.loginService.login(this.credentials).subscribe((res) => {
console.log(res)
})
}
我希望网络应用程序存储 cookie 并在每个请求中发送它,以便后端可以检查您是否实际登录
【问题讨论】: