我正在尝试使用 HttpClient 发出 API 请求以下载 CSV 文件。由于 ForgeRock 身份验证需要不记名令牌,我不得不从 Axios 切换到 HttpClient。我遇到了返回的响应没有 response.data 的问题。我在哪里可以找到要下载到 CSV 的数据?
我的代码:
fetchCSV = date => {
const url = "https://<URLdownloadLink>?runDate="+date;
const method = "GET";
HttpClient
.request({
url,
method,
bypassAuthentication: false,
responseType: 'blob',
init: {},
timeout: 5000
})
.then((response) => {
console.log("data", response)
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'Asset Manager.csv');
document.body.appendChild(link);
link.click();
link.remove();
})
.catch(error => {
console.log("error", error);
})
}