方式一:将中文文件名用ISO-8859-1进行重新编码,如headers.add("Content-disposition","attachment;filename="+new String("中国".getBytes("UTF-8"),"ISO-8859-1")+".txt"); 方式二:可以对中文文件名使用url编码,如headers.add("Content-disposition","attachment;filename="+URLEncoder.encode("中国","UTF...
Content-Disposition: attachment;filename="测试.txt" 然后,各浏览器支持的对应编码格式为: 1. IE浏览器,采用URLEncoder编码 2. Opera浏览器,采用filename*方式 3. Safari浏览器,采用ISO编码的中文输出 4. Chrome浏览器,采用Base64编码或ISO编码的中文输出 5. FireFox浏览器,采用Base64或filename*或ISO编码的中...
步骤1:创建一个HttpHeaders对象 首先,我们需要创建一个HttpHeaders对象,用于保存我们要设置的Content-Disposition属性。 HttpHeadersheaders=newHttpHeaders(); 1. 步骤2:设置Content-Disposition的filename属性 接下来,我们需要设置Content-Disposition的filename属性。假设我们要设置的文件名为"中文文件名.txt",可以按照以下...
response['Content-Disposition'] = 'attachment; filename=' + filename.encode('utf-8).decode('ISO-8859-1')就ok了 常用浏览器解析格式。 IE浏览器,采用URLEncoder编码 Opera浏览器,采用filename*方式 Safari浏览器,采用ISO编码的中文输出 Chrome浏览器,采用Base64编码或ISO编码的中文输出 FireFox浏览器,采用B...
因此兼容规则设置为 ie: urlEncode , opera\firefox : filename*, safari\chrome: iso-8859-1 ⽐较合适 --- 割~~~ --- 浏览器能正确识别的编码格式,只要按照这样的编码来设置对应的Content-Disposition,那么应该就不会出现中⽂⽂件名的乱码问题了。⾸先,Content-Disposition值可以有以下⼏种编码...
文件下载_中文乱码:"Content-disposition","attachment; filename=中文名 2017-10-20 17:33 −Response.setHeader(“Content-Disposition”, “attachment; filename=” + fileName+”.xls”); 如果file.Name为中文则乱码。解决办法是 方法1: response.setHeader(“Con... ...
append(line) response = HttpResponse(save_virtual_workbook(wb), content_type='application/octet-stream') response['Content-Disposition'] = 'attachment; filename=somefile.xls' return response 其中用英文的文件名如animal.xls,浏览器显示正常,但是用了中文后,就是默认的文件名,如下载.xls,或者如果我用...
file_name = '测试.txt' content = ... response = HttpResponse(content, content_type='application/octet-stream') response['Content-Disposition'] = "attachment; filename*=utf-8''{}".format(escape_uri_path(file_name)) return response