Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 包含承载令牌时,HttpClient请求失败_Angular_Metronic - Fatal编程技术网

Angular 包含承载令牌时,HttpClient请求失败

Angular 包含承载令牌时,HttpClient请求失败,angular,metronic,Angular,Metronic,当我向API URL提交post请求时。每次包含授权时都会失败。当我尝试使用API登录时。它很好用。但后来。当我尝试使用其身份验证令牌获取所有用户时。它无法满足请求。我正在使用HttpClient。(@angular/common/http) const httpHeaders=新的httpHeaders({ “访问控制允许凭据”:“true”, “访问控制允许来源”:“*”, “内容类型”:“应用程序/json”, 'Authorization':'Bearer'+environment.au

当我向API URL提交post请求时。每次包含授权时都会失败。当我尝试使用API登录时。它很好用。但后来。当我尝试使用其身份验证令牌获取所有用户时。它无法满足请求。我正在使用HttpClient。(@angular/common/http)

const httpHeaders=新的httpHeaders({
“访问控制允许凭据”:“true”,
“访问控制允许来源”:“*”,
“内容类型”:“应用程序/json”,
'Authorization':'Bearer'+environment.authTokenKey});
const users=this.http.post(API_users_URL,null,{headers:httpHeaders});
返回用户;

我是新来的。对不起,我忘了提这个问题。你说的失败是什么意思?有错误吗?请求已发送?您是否添加了任何
拦截器
?很可能您需要一个并添加
with credentials:true
@KamLar我也尝试过使用with credentials。但没有效果。@Elias Soares只是“失败了”,我是新来的。对不起,我忘了提这个问题。你说的失败是什么意思?有错误吗?请求已发送?您是否添加了任何
拦截器
?很可能您需要一个并添加
with credentials:true
@KamLar我也尝试过使用with credentials。但没有效果。@Elias Soares只是“失败”
const httpHeaders = new HttpHeaders({ 
            'Access-Control-Allow-Credentials': 'true',
            'Access-Control-Allow-Origin': '*',
            'Content-Type': 'application/json',
            'Authorization':  'Bearer ' + environment.authTokenKey });
        const users = this.http.post<User[]>(API_USERS_URL, null, { headers: httpHeaders});
        return users;