我正在尝试从Angular连接到C#WEB API . 我已经配置了服务器以允许CORS . 实际上,服务器方法已被命中并正确返回数据,但Angular一直向我发送错误
'无法加载http:// localhost:54918 / ohmioapi / token:请求的资源上没有'Access-Control-Allow-Origin'标头 . 原因'http:// localhost:4200'因此不允许访问 .
事实上,如果我停止API,得到相同的错误,所以我得出结论,angular阻止返回的数据 . 这是我的Angular代码:
let headers = new HttpHeaders();
headers.append('Content-Type', 'application/json');
headers.append('Content-Type', 'application/json');
headers.append('Access-Control-Allow-Origin', '*');
let body = {"username": user, "password": password, "clientid": clientid, "empresaid": empresaid};
this._http.post(this.urlAPI+'token', body, {
headers: headers,
}).subscribe((respuesta:any) => {
this._token = new Token(respuesta.access_token, respuesta[".expires"]);
localStorage.setItem('usertoken', JSON.stringify(this._token));
console.log("Token obtenido: "+this._token);
return;
})
有谁能够帮我?