如何删除由 spring-boot 生成的 Content-Type 标头中的 charset=utf-8 [英] How to remove charset=utf-8 in a Content-Type header, generated by spring-boot

查看:37
本文介绍了如何删除由 spring-boot 生成的 Content-Type 标头中的 charset=utf-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 spring-boot 中发送一个 mp4 文件作为响应正文.我尝试使用以下方法将 Content-Type 标头设置为 video/mp4:

I'm trying to send an mp4 file as a response body in spring-boot. I've tried setting the Content-Type header to video/mp4 using the following methods:

  1. RequestMapping 注解参数:

  1. A RequestMapping annotation parameter:

@RequestMapping(value = "/movie.mp4", method = RequestMethod.GET, produces = "video/mp4")

  • 通过HttpHeaders手动设置一个header值,传递给返回ResponseEntity.

  • Manually setting a header value via HttpHeaders, passed to return ResponseEntity.

    每次得到的header如下:

    Each time the resulting header is as follows:

    Content-Type:video/mp4; charset=UTF-8
    

    如何去掉 charset=UTF-8 后缀?

    推荐答案

    经过调试,发现 HttpEncodingAutoConfiguration 设置了 spring.http.encoding.force=true.如果您在 application.properties 中将此设置为 false,则字符集将被省略.

    It took some debugging, but I found that HttpEncodingAutoConfiguration sets spring.http.encoding.force=true. If you set this to false in your application.properties, the charset will be omitted.

    这篇关于如何删除由 spring-boot 生成的 Content-Type 标头中的 charset=utf-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆