使用HTTP拦截器的Changin http响应对象

时间:2019-10-22 17:03:17

标签: angular

我正在尝试使用Angular-6中的HTTP拦截器更改响应

intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    console.log('request', request);
    const httpsReq = request.clone({
        url: request.url.replace("http://xx.xx.xx.xx:8085/onlinetest/api/v1/signin", "http://jsonplaceholder.typicode.com/todos/1"),
        method: 'GET'
      });

    //   return of(new HttpResponse({ status: 200, body: this.returnData }));


      return next.handle(httpsReq).pipe(
        // There may be other events besides the response.
        filter(event => event instanceof HttpResponse),
        tap((event: HttpResponse<any>) => {
          return {status: 200, data: 'hello'}
        })
      );        
}

这是给我来自jsonplaceholder api的响应,虽然我想看看{status: 200, data: 'hello'},请帮忙。

0 个答案:

没有答案