angular未在请求标头上发送正确的标头
我是一个使用angular的新手,我正在努力学习一点,但我不能使用令牌进行简单的获取。我做了很多研究,最后总是得到这段代码 对于我的后端,我使用Kotlin/Springboot并配置了Cors 即使如此,当我尝试做这个请求时,我还是会得到这个错误angular未在请求标头上发送正确的标头,angular,Angular,我是一个使用angular的新手,我正在努力学习一点,但我不能使用令牌进行简单的获取。我做了很多研究,最后总是得到这段代码 对于我的后端,我使用Kotlin/Springboot并配置了Cors 即使如此,当我尝试做这个请求时,我还是会得到这个错误 export class AccountService { endpoint = 'http://localhost:5000/api-v1/account/list' constructor(private http: HttpClie
export class AccountService {
endpoint = 'http://localhost:5000/api-v1/account/list'
constructor(private http: HttpClient) { }
list() {
const token = sessionStorage.getItem('token') // I'm getting the token correctly
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Access-Control-Allow-Headers': '*',
'Authorization': token,
}
return this.http.get<any[]>(this.endpoint, { headers: headers }) } }
我真的不知道我们是否还需要补充什么
- 角度CLI:7.3.1
- 节点:12.13.0
- 角度:7.2.4
response.setHeader("Access-Control-Allow-Origin", "http://localhost:4200")
到
这应该行。您在进行更改后是否重新启动了服务?我建议您是否可以修改描述,因为这完全不是angular的问题。快乐学习:)
response.setHeader("Access-Control-Allow-Origin", "http://localhost:4200")
response.setHeader("Access-Control-Allow-Origin", "*")