axios发出请求,获取后端图片文件流,中文乱码问题,急需解决,非常感谢!!
java代码:
@RequestMapping("/showDiagram")
// 显示流程图
public String showDiagram(HttpServletResponse response) {
OutputStream out = null;
String processInstanceId = "5001";
try {
// HttpServletResponse response = ServletActionContext.getResponse();
InputStream is = this.getDiagram(processInstanceId);
response.setContentType("image/png;charset=utf8");
out = response.getOutputStream();
out.write(getImgByte(is));
out.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
out.close();
} catch (Exception e) {
}
}
return null;
}
vue 代码:
greet() {
var url = '/sde/showDiagram/';
this.$axios.post(url, {
responseType:'arraybuffer',
// headers: {'Content-Type': 'multipart/form-data;charset=UTF-8'},
}).then(res => {
console.log(res.data);
// document.getElementById("imgTest").src = res.data;
})
}