<!DOCTYPE html> <htmllang="en"> <head> <metacharset="UTF-8"> <metaname="viewport"content="width=device-width, initial-scale=1.0"> <title>测试</title> </head> <body> <buttononclick="queryPdfData()">下载文件</button> </body> <script> functionqueryPdfData(){ fetch("http://60.190.3.170:8091/jiaLin/getPreFile?type=0&keyword=LS23000173&fileType=3",{header:{'token':'bea7c7a3716f1bac133988fde350c02e'}}).then((response) =>response.body) .then((rb) => { const reader = rb.getReader(); returnnewReadableStream({ start(controller) { // The following function handles each data chunk functionpush() { // "done" is a Boolean and value a "Uint8Array" reader.read().then(({ done, value }) => { // If there is no more data to read if (done) { controller.close(); return; } // Get the data and send it to the browser via the controller controller.enqueue(value); // Check chunks by logging to the console push(); }); } push(); }, }); }) .then((stream) =>{ // Respond with our stream returnnewResponse(stream) } ) .then((response) => response.blob()) .then((blob) => { const url=window.URL.createObjectURL(newBlob([blob], { type: 'application/pdf' })) window.open(url) }) } </script> </html>