Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用rxjs从后端api获取头属性?_Rxjs_Angular7_Angular Httpclient - Fatal编程技术网

如何使用rxjs从后端api获取头属性?

如何使用rxjs从后端api获取头属性?,rxjs,angular7,angular-httpclient,Rxjs,Angular7,Angular Httpclient,我正在从后端获取文件流。标头保留扩展名为的文件名。但如何在前端获得这些属性。这是我的代码,没有得到值,也没有错误 downloadFile(id:number):Observable<any> { const options = { responseType: 'blob' as 'json' } return this.http.get<any>(environment.baseUrl+`CourseFileUpload/${id}`

我正在从后端获取文件流。标头保留扩展名为的文件名。但如何在前端获得这些属性。这是我的代码,没有得到值,也没有错误

downloadFile(id:number):Observable<any> {

        const options = { responseType: 'blob' as 'json' }

        return this.http.get<any>(environment.baseUrl+`CourseFileUpload/${id}`, options)
        .pipe(
            map((file) => {
                console.log('header', file.headers('Content-Disposition')); //not getting header value...!?
                return new Blob([file], {type: "application/octet-stream"})
            }),
            catchError(this.handleError)
        )
    }
下载文件(id:number):可观察{
常量选项={responseType:'blob'作为'json'}
返回此.http.get(environment.baseUrl+`CourseFileUpload/${id}`,选项)
.烟斗(
映射((文件)=>{
console.log('header',file.headers('Content-Disposition');//未获取头值。。。!?
返回新Blob([file],{type:“application/octet stream”})
}),
catchError(this.handleError)
)
}
有人帮我吗

我尝试过这样的建议:

downloadFile(id:number):Observable<any> {

        const headers = new HttpHeaders({ observe: 'response'});
        const options = { responseType: 'blob' as 'json', headers:headers  }

        return this.http.get<any>(environment.baseUrl+`CourseFileUpload/${id}`,  options )
        .pipe(
            map(resp => {
                if(resp.headers){
                    const keys = resp.headers.keys();
                    console.log('file',  keys); //nothing consoles!?
                }

                return new Blob([resp], {type: "application/octet-stream"})
            }),
            catchError(this.handleError)
        )
    }
下载文件(id:number):可观察{
const headers=新的HttpHeaders({observe:'response'});
const options={responseType:'blob'作为'json',headers:headers}
返回此.http.get(environment.baseUrl+`CourseFileUpload/${id}`,选项)
.烟斗(
映射(resp=>{
如果(分别为标题){
const keys=resp.headers.keys();
console.log('file',key);//没有控制台!?
}
返回新Blob([resp],{type:“application/octet stream”})
}),
catchError(this.handleError)
)
}

没有得到回应。请任何人帮助我获取响应标题?

从中,您需要在选项中添加
观察:“响应”
,以访问完整响应对象。

您可以访问响应对象中的标题,看看这个例子@dudadub-我添加了有问题的代码部分。仍然没有收到任何响应头。。你能看一下我更新的代码并给我建议正确的方法吗?顺便问一下,
this.http
的类型是什么?我正在从后端获取未知对象。其中我需要获取我的数据。