在拦截器中统一添加多个请求头数据

在拦截器中统一添加多个请求头数据

import {
    
     Injectable } from '@angular/core';
import {
    
     HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from '@angular/common/http';
import {
    
     Observable } from 'rxjs';

@Injectable()
export class HeaderInterceptor implements HttpInterceptor {
    
    

    public intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    
    
    const authReq = req.clone({
    
    
      setHeaders: {
    
    
        'Access-Control-Allow-Origin': '*',
        'X-Emp-No': this.rest.getEmpNo(),
        'X-Auth-Value': this.rest.getToken(),
      }
    });
        return next.handle(authReq);
    }
}

猜你喜欢

转载自blog.csdn.net/ActiveXObject/article/details/115139422