Post请求数据流下载

后的后台再做批量导出的时候因为数据量的问题所以需要时用到批量导出的功能,所以这时候需要用到post传参

ajax请求在文件下载方面会有一定的限制 所以这时候就需要使用到 原生js请求的XMLHttpRequest方法

const params = {
  name:'123',
  idlist: ['111','222']
}
 let url= '你的借口名称全名!包括https://www.xxx.com?access_token=' + token;
// url需要带上token
 let xhr = new XMLHttpRequest();  
xhr.open('POST', url, true);
      xhr.responseType = "blob";
      xhr.setRequestHeader("client_type", "DESKTOP_WEB");
      xhr.setRequestHeader('Content-Type', 'application/json');
      xhr.onload = function () {
          if (this.status == 200) {
              var blob = this.response;
              var objecturl = URL.createObjectURL(blob);
              window.location.href = objecturl;
          }
      }
      xhr.send(JSON.stringify(params));  // 发送请求携带参数

以上就是使用js完整的一个post 数据流下载

原文地址:https://www.cnblogs.com/wangjiahui/p/13344883.html