1

我正在尝试将 csv 作为流从服务器发送到客户端。交换和下载工作正常,但是,chrome 总是在控制台中记录以下内容:

Resource interpreted as Document but transferred with MIME type text/csv

客户端请求如下所示:

<form class="feedbackCSVGenerator" method="get" action="my/url">
    <button type="submit" role="button"><span>Download as CSV</span></button>
</form>

和服务器端实现:

response.setContentType("text/csv");
response.setHeader("Content-Disposition",
            "attachment;filename=Feedback.csv");
response.setContentLength("Hello world".getBytes().length);
try {
    ServletOutputStream outStream = response.getOutputStream();
    outStream.write("Hello world".getBytes());
    outStream.close();
    response.flushBuffer();
} catch (IOException e) {
    //
}

我是否应该选择不同的 MIME 类型,或者我可以设置另一个响应标头以防止此消息弹出?好像没什么影响,但还是...

4

0 回答 0