如何从GET申请中获取pdf档案的字节数组?

时间:2019-06-17 14:51:30

标签: angular angular-httpclient

我有一个api重命名了pdf文件中的字节数组,但是当我执行get请求时,我无法获取该字节数组。以下消息出现在浏览器控制台中:

  

错误{…}错误:{…}错误:语法错误:“ JSON.parse:意外   JSON数据第1行第1列的字符”       角8文本:“%PDF-1.5 \ n%����\ n3 0 obj \ n <> stream \nx���Mj�0\u0010��:。[:\ u001bU?~~- �bj�\ u000b]�X\ t \u000eN�8!!s�^��\ u0017u \u000b�} 8 \ u000ch xo�'�\u0013yqD*\u0018��J�:�N\u0004\u0016a���\n��\u0005ܞ<�rp\u0006�!��킶�0���M�[\u001a\u001bh˨�?f\u0013̬�4[\u0012��+r_\u0017���:��\u000c�;kW\u001fm/�X�@n%M,474�������qC�<]>�,�g\u0013��A)C�\u0018\"f�DB\"��\u001c!\u0014G_W���\u0013�E�\u0018�Ծ�,�\u0007b��0��?��7�_。 R \ nendstream \ nendobj \ n1   0   obj \ n <> /目录   3 0 R /类型/页面/资源<> / ProcSet [/ PDF   / Text / ImageB / ImageC / ImageI] / Font <>>> / Parent 4 0   R / MediaBox [0 0 595 842] >> \ nendobj \ n5 0 obj \ n [1 0 R / XYZ 0852   0] \ nendobj \ n2 0   obj \ n <> \ nendobj \ n4   0 obj \ n <> \ nendobj \ n6 0   obj \ n <> \ nendobj \ n7 0 obj \ n <> \ nendobj \ n8 0 obj \ n <>>> \ nendobj \ n9 0   obj \ n <> \ nendobj \ nxref \ n0 10 \ n0000000000 65535 f \ n0000000301 00000 n \ n0000000577 00000 n \ n0000000015 00000 n \ n0000000665 00000 n   \ n0000000542 00000 n \ n0000000728 00000 n \ n0000000782 00000 n   \ n0000000814 00000 n \ n0000000917 00000 n \ ntrailer \ n << 0f3db8438dad491480ff1017eef9db67>] / Root   8 0 R /大小10 >> \ nstartxref \ n1125 \ n %% EOF \ n“:对象{…   }标头:Object {normalizedNames:Map(0),lazyUpdate:null,   lazyInit:lazyInit()}消息:“解析过程中的Http失败   http://localhost:9000/jasper/relatorio/testejasper“的名字:   ``HttpErrorResponse''ok:错误状态:200 statusText:“ OK”   网址:“ http://localhost:9000/jasper/relatorio/testejasper”   :对象{构造函数:HttpErrorResponse()}   core.js:15724       角度4       RxJS 5       角度11

如何在不发生此错误的情况下获取此字节数组?

我还尝试过将此配置传递给请求:

new HttpHeaders({Accept: 'application/pdf', 'Content-Type': 'application/pdf', responseType: 'blob'});

2 个答案:

答案 0 :(得分:1)

responseType不应位于标头中。这是一个单独的参数。

this.http.get(url, { headers: ... , responseType: 'blob' })

答案 1 :(得分:0)

尝试

'responseType':'blob'为'json'

相关问题