我知道http 302
响应是由浏览器直接处理的,因此您无法访问源代码中的任何请求属性。但我想知道是否有任何方法可以拦截302重定向响应。让我解释一下自己:
302 Location: B
302
响应,然后转到B 这是我的Angular http拦截器代码:
@Injectable()
export class CasInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
console.log('->Interceptor');
console.log(req);
return next.handle(req).map((event: HttpEvent<any>) => {
const response = event as HttpResponseBase;
console.log('<-Interceptor');
console.log(response);
return event;
});
}
}
答案 0 :(得分:0)
您应该从http响应中获得完整的标头。
{observe:“ response”}是有角度的http客户端的魔术参数。 所以尝试这个
this.http
.get<any>(requestURL,{observe:"response"})
.subscribe(
data => {
console.log(data.header); //you will see full header here
console.log(data.url); // you can see redirect url from backend and handle it whatever you want
},
err => {
console.log(err)
}