Angular 6 无法读取 HttpClient 中的 Octet-stream 错误消息:"Http failure during parsing for..."
Angular 6 Unable to read Octet-stream in HttpClient Error message: "Http failure during parsing for..."
我想使用 angular 6 HttpClient (@angular/common/http) 向服务器发出非 json 请求以获取 Octet-stream 。下面是我的代码。
getFile(file: any) {
let headers: new HttpHeaders({
'Content-Type': 'application/octet-stream',
'Accept':'application/octet-stream',
'Authorization': 'Bearer ' + data.token
})
return this.http.get<any>(this.baseUrl + '/getfile/'+file, headers);
}
但这给了我 JSON 解析错误。
"HttpErrorResponse", message: "Http failure during parsing for.....
ERROR
{…}
error: {…}
error: SyntaxError: "JSON.parse: unexpected character at line 1 column 1 of the JSON data"
非json怎么读?
试试这个:
let headers = new HttpHeaders({
'Authorization': 'Bearer ' + data.token
});
return this.http.get<any>(this.baseUrl + '/getfile/'+file, {headers:headers, responseType: 'blob'});
我想使用 angular 6 HttpClient (@angular/common/http) 向服务器发出非 json 请求以获取 Octet-stream 。下面是我的代码。
getFile(file: any) {
let headers: new HttpHeaders({
'Content-Type': 'application/octet-stream',
'Accept':'application/octet-stream',
'Authorization': 'Bearer ' + data.token
})
return this.http.get<any>(this.baseUrl + '/getfile/'+file, headers);
}
但这给了我 JSON 解析错误。
"HttpErrorResponse", message: "Http failure during parsing for..... ERROR {…} error: {…} error: SyntaxError: "JSON.parse: unexpected character at line 1 column 1 of the JSON data"
非json怎么读?
试试这个:
let headers = new HttpHeaders({
'Authorization': 'Bearer ' + data.token
});
return this.http.get<any>(this.baseUrl + '/getfile/'+file, {headers:headers, responseType: 'blob'});