我有一个很大的应用程序,到现在为止,它只有一个http服务器来发出请求。
在app.module中,我有以下拦截器:
providers: [
{
provide: LocationStrategy,
useClass: HashLocationStrategy
},
{
provide: HTTP_INTERCEPTORS,
useClass: JwtInterceptor,
multi: true
},
{
provide: HTTP_INTERCEPTORS,
useClass: ErrorInterceptor,
multi: true
}],
问题是,我需要添加一个从外部服务到端点的API调用,我希望我可以抵制这个拦截器,只针对这个API调用。
getAllCesiumModels(params?: apiModels.GetAllCesiumRequest): Observable<apiModels.GetAllModelsResponse> {
return this.httpClient.get<any>(`https://api.cesium.com/v1/assets`, {headers: { Authorization: `Bearer ${params.accessToken}` }});
}
有没有一种方法,在不更改所有应用程序的情况下,使这个get请求不跳过拦截器?
谢谢
发布于 2020-01-22 03:15:16
我不确定这是否有效,但你可以试一试。
export class JwtInterceptor implements HttpInterceptor {
public intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(request).pipe(
catchError((err) => {
if(request.url.indexOf("your web app url")==-1)
{
return EMPTY;
}
})
)
}
}
发布于 2020-01-22 04:22:56
在服务级
bypassedClient: HttpClient
constructor(
private handler: HttpBackend
) {
this.bypassedClient = new HttpClient(handler);
}
makeCall(){
this.bypassedClient.post(this.apiURL + Constant.API.authenticate, params)
.subscribe((res)=> console.log(res))
}
https://stackoverflow.com/questions/59852053
复制相似问题