此调用是通过我的服务进行的,以检索用于下载文档的URL:
return this.http.get(this.buildUrl('issueDocument', 'get', pathParams), { responseType: 'blob', params: queryParams });
this.http.get中的buildURL工作正常我已经测试过了,但是这个.http.get的返回会引发这个错误
ERROR TypeError: Cannot read property 'length' of undefined
at HttpHeaders.applyUpdate (http.js:322)
at eval (http.js:269)
at Array.forEach (<anonymous>)
at HttpHeaders.init (http.js:269)
at HttpHeaders.forEach (http.js:368)
at Observable.eval [as _subscribe] (http.js:2172)
at Observable._trySubscribe (Observable.js:172)
at Observable.subscribe (Observable.js:160)
at CatchOperator.call (catchError.js:80)
at Observable.subscribe (Observable.js:157)
关于发生了什么的任何想法?我无法理解为什么会发生这种情况......在开发工具网络标签中,它甚至没有显示网络电话......
答案 0 :(得分:1)
在显示的错误消息中,您只需要将undefined
传递到.set(...)
标题中。
我这样做:
getHeaders() {
const headers = new HttpHeaders();
headers
.set('Content-Type', 'application/json')
.set('Authorization', localStorage.getItem('token') || '');
return headers;
}