加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular5 – 如何从角度为5的URL下载pdf文件

发布时间:2020-12-17 17:57:29 所属栏目:安全 来源:网络整理
导读:我目前在这个问题上花了一天时间,仍然无法从角度5的网址下载文件 leadGenSubmit() { return this.http.get('http://kmmc.in/wp-content/uploads/2014/01/lesson2.pdf',{responseType:ResponseContentType.Blob}).subscribe((data)={ console.log(data); var
我目前在这个问题上花了一天时间,仍然无法从角度5的网址下载文件

leadGenSubmit() {

    return this.http.get('http://kmmc.in/wp-content/uploads/2014/01/lesson2.pdf',{responseType:ResponseContentType.Blob}).subscribe((data)=>{
        console.log(data);
        var blob = new Blob([data],{type: 'application/pdf'});
        console.log(blob);
        saveAs(blob,"testData.pdf");
    },err=>{
        console.log(err);
        }
    )
}

当我运行上面的代码时,它显示以下错误

ERROR TypeError: req.responseType.toLowerCase is not a function
    at Observable.eval [as _subscribe] (http.js:2187)
    at Observable._trySubscribe (Observable.js:172)

如何解决这个问题.任何人都可以发布正确的代码从角度5的网址下载pdf文件?

解决方法

我认为你应该像这样定义header和responseType:

let headers = new HttpHeaders();
headers = headers.set('Accept','application/pdf');
return this.http.get(url,{ headers: headers,responseType: 'blob' });

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读