当我启动角度应用程序时如何获取第一个http请求的标头(http://localhost:4200/)

jol*_*lis 6 header http angular-http-interceptors angular

我希望获取第一个 http 请求的标头http://localhost:4200/

为了启动我的应用程序,我转到 URL http://localhost:4200/,我想在控制台中写入 http 入口的标头。

有谁知道这是否可能?

我尝试使用拦截器,但我只拦截应用程序的 http 请求和响应排序。

sab*_*ker 0

默认情况下, Angular HttpClient仅观察结果,您可以使用它{observe: 'response'}来获取完整响应并从中获取标头。

 this.http.get('/', { observe: 'response' }).subscribe(response => {
    console.log(response.headers.get('SAMPLEITEM'))
 });
Run Code Online (Sandbox Code Playgroud)

记录在这里