我将 ionic5 与 Angular 一起使用。我的 API 将 pdf 作为 Blob 对象返回。使用 Angular Http(适用于浏览器)时,我能够获得 Blob 响应
let headers =
new HttpHeaders({
'Accept': 'application/pdf',
'Content-type': 'application/json',
'Authorization': 'Bearer token',
'Access-Control-Allow-Origin': 'localhost'
});
return this.httpClient.post(
apiURL,
JSON.stringify(myBodyParamsObj),
{headers: headers, responseType: 'blob'}
);
但是在使用离子原生 http 时我无法获得响应(由于使用 Angular Http 时的 CORS 问题,需要使用它在设备中运行应用程序)。尝试如下 -
this.nativeHttp.setDataSerializer("raw"); // Tried other options like json etc. but none works
this.nativeHttp.post(apiURL, params, { 'Authorization': myAuthHeaderObj, 'Content-Type': 'application/json', 'Accept': 'application/pdf', responseType: 'blob'});
也尝试过this.nativeHttp.sendRequest
,但没有成功。
请帮忙