首页 > 解决方案 > 在 Angular 8 的标头中传递正确的令牌请求时被禁止 403,

问题描述

我正在使用 get 方法在 header 中发送 4 个数据(id、token、ROLE、EMPCODE),

我收到错误

错误 HttpErrorResponse {标头:HttpHeaders,状态:403,状态文本:“禁止”

我的令牌是正确的,我在 Postman 中检查过, 我收到状态为 200 的响应,但我在我的项目中遇到了这个问题

我正在分享我的服务文件代码

employeeData( id ,   token , role , employeeCode){
 let headers = new HttpHeaders();
  headers.append('id', id);
  headers.append('TOKEN', token);
  headers.append('ROLE', role);
  headers.append('EMPCODE' , employeeCode);
  headers.append( 'Content-Type' ,  'application/json');


  return this.http.get(this.emp_data, {headers: headers});

}

我正在从订阅获取响应的 Component 共享代码。

viewdetails(){

     this.rest.employeeData(this.userId,this.token,this.role, this.employeeCode).subscribe(
      result => {
        console.log('hello');
        console.log(result);
      })
}

当我签入浏览器的网络标头时,我可以检查我在请求中传递的标头没有通过那里。

标签: angularangular8angular-httpclientangular-http

解决方案



推荐阅读