angular知识系列:发送http请求时带上cookie

江阳羽
2023-12-01

参考:

        angular2 services - angular 2 http withCredentials - Stack Overflow

结论:

        1.可以在http请求时添加options

        2.可以在拦截器统一对http请求进行封装

export class CustomHttpInterceptor implements HttpInterceptor {

  constructor() {}

  intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    request = request.clone({
      withCredentials: true
    });

    return next.handle(request);
  }
}

 类似资料: