【问题标题】:Spring boot to allow any content type in headers for GET requestSpring Boot 允许 GET 请求标头中的任何内容类型
【发布时间】:2022-12-21 03:20:58
【问题描述】:

我收到以下错误,因为客户端将内容类型作为 multipart/form-data 发送,而我的控制器方法是 GET。

org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found

spring boot 中有没有一种方法允许控制器接受标头中的任何内容类型?

@GetMapping("/logic")
public ResponseEntity<HttpStatus> appLogic(){
//application logic 
}

【问题讨论】:

    标签: spring spring-boot


    【解决方案1】:

    为什么你的URI是/content-type?这是故意的吗?如果是,则令人困惑。 “content-type”是 HTTP 请求和响应的标头。在请求中,此标头告诉服务器端在请求正文中发送的实际数据类型是什么。由于方法 GET 不允许请求正文,因此 GET 请求的此标头毫无意义。您的错误告诉您请求通知服务器(通过将标头content-type设置为值multipart/form-data)请求主体的类型为multipart/form-data,但请求不包含任何此类数据,并且自@以来就无法包含它987654327@不能有尸体。如果您需要在请求正文中传递一些信息,您需要使用方法 POSTPUT

    【讨论】:

    • 我保留了 url 进行测试。更新了网址。有没有像 GET 这样的方法可以忽略标头中的任何内容类型?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-05
    • 2018-05-07
    • 2020-02-24
    • 2023-04-02
    • 2017-08-07
    • 2017-03-05
    相关资源
    最近更新 更多