Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.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
在特定请求HttpClient 5上禁用标头?_Httpclient_Angular5 - Fatal编程技术网

在特定请求HttpClient 5上禁用标头?

在特定请求HttpClient 5上禁用标头?,httpclient,angular5,Httpclient,Angular5,我已将我的应用程序从ng4升级到NG5V-5.2.9。我已经为每个请求设置了标题。但在我的应用程序中,有些请求不支持标题,所以如何禁用特定请求(而不是每个请求)的标题 以前在ng4中我使用http,但现在面临的问题是ng5不再支持http setHeader.ts import { Injectable } from '@angular/core'; import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor, HttpErrorR

我已将我的应用程序从ng4升级到NG5V-5.2.9。我已经为每个请求设置了标题。但在我的应用程序中,有些请求不支持标题,所以如何禁用特定请求(而不是每个请求)的标题

以前在ng4中我使用http,但现在面临的问题是ng5不再支持http

setHeader.ts

import { Injectable } from '@angular/core';
import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor, HttpErrorResponse } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/catch';
import 'rxjs/add/observable/throw';

 @Injectable()
 export class AddHeaderInterceptor implements HttpInterceptor {
     intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {

    let currentUser = JSON.parse(localStorage.getItem('currentUser'));
    if (currentUser && currentUser.token) {
        request = request.clone({
            setHeaders: { 
                Authorization: `Bearer ${currentUser.token}`,
                Ip:currentUser.Ip
            }
        });
    }
    return next.handle(request);
}
}
import { HTTP_INTERCEPTORS } from '@angular/common/http';

@NgModule({
   providers: [{
   provide: HTTP_INTERCEPTORS,
   useClass: AddHeaderInterceptor,
   multi: true,
  }],
})
export class AppModule {}
基本上,报头用于令牌和自动化,一些API不需要授权,因此不需要报头,通过使用setHeader,它适用于所有API调用。我的浏览器控制台上有HttpErrorResponse。不需要的地方

谢谢