简体   繁体   English

多部分/表单数据之间的空白问题; & 内容类型标题中的边界

[英]White-space issue between multipart/form-data; & boundary in Content-Type Header

I've developed Spring boot(v1.5.2) rest api and using spring-boot-starter-undertow embedded server to run the application.我开发了 Spring boot(v1.5.2) rest api 并使用 spring-boot-starter-undertow 嵌入式服务器来运行应用程序。 One of the operation has upload file feature (method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE).其中一项操作具有上传文件功能(method = RequestMethod.POST,consumes = MediaType.MULTIPART_FORM_DATA_VALUE)。

The application is working fine as expected when testing with postman with auto-generated headers like Content-Type, Content-Length, etc..当使用邮递员使用自动生成的标题(如 Content-Type、Content-Length 等)进行测试时,该应用程序按预期工作正常。

But the issue is, client/consumer app is sending the Content-Type as multipart/form-dat a;b oundary=----xyz---- (without space between multipart/form-data; & boundary) and the request is failing with 400 Bad request and it's not reaching the controller.但问题是,客户端/消费者应用程序将 Content-Type 作为 multipart/form-dat a; boundary=----xyz----(在 multipart/form-data; 和边界之间没有空格)和请求因 400 Bad request 而失败,并且没有到达控制器。

But the auto-generated postman header has white-space.但是自动生成的邮递员标题有空格。 (multipart/form-dat a; b oundary=----xyz---) which is working fine and when we override this header to have that whitespace then it's not working in postman too. (multipart/form-dat a; b oundary=----xyz---) 工作正常,当我们覆盖这个标题以获得那个空格时,它也不适用于邮递员。 So the issue is with the pattern of the Content-Type.所以问题在于内容类型的模式。

Few things I tried are, I added Filters and override the HttpServletRequestWrapper to modify the content-type header before the request reach the controller but the solution is not working.我尝试的几件事是,我添加了过滤器并覆盖 HttpServletRequestWrapper 以在请求到达控制器之前修改内容类型标头,但解决方案不起作用。 I tried AOP as well but there are not setHeader method to set/update request headers.我也尝试过 AOP,但没有 setHeader 方法来设置/更新请求标头。

Could you please share your experiences or ideas on how to handle this scenario in server application(producer) without touching the consumer application.您能否分享您关于如何在不触及消费者应用程序的情况下在服务器应用程序(生产者)中处理这种情况的经验或想法。

I still couldn't figure out the issue/root-cause with undertow, but when I changed the embedded server to spring-boot-starter-jetty then my requests with/without white space between multipart/form-data;我仍然无法通过 undertow 找出问题/根本原因,但是当我将嵌入式服务器更改为 spring-boot-starter-jetty 时,我的请求在 multipart/form-data 之间有/没有空格; & boundary in content-type is working fine. & 内容类型中的边界工作正常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将带有“ Content-Type”标题的数据发布为“ multipart / form-data” - How to post data with “Content-Type ” header as “multipart/form-data” 使用 header Content-Type:multipart/form-data 发送 java POST 请求? - Send the java POST request with header Content-Type:multipart/form-data? "Quarkus-resteasy-multipart 找不到内容类型多部分\/表单数据类型的编写器" - Quarkus-resteasy-multipart could not find writer for content-type multipart/form-data type spring rest webservices使用application / json content-type返回multipart / form-data - spring rest webservices return multipart/form-data with application/json content-type 更新 Android 中多部分表单数据请求的默认内容类型 - Update default Content-Type for multipart form-data request in Android 如何在 RestAssured 的正文中发送带有表单数据的 POST,并设置具有特定内容类型的多部分 - How to send a POST with form-data in Body in RestAssured setting multipart with a specific content-type Java Spring:不支持内容类型“multipart/form-data;boundary;charset=UTF-8” - Java Spring: Content type 'multipart/form-data;boundary ;charset=UTF-8' not supported 有什么办法可以通过附件的内容类型来过滤请求(multipart / form-data)? - Is there any way to filter request (multipart/form-data) by content-type of attached file? 内容类型 'multipart/form-data;boundary=----...;charset=UTF-8' 不支持 - Content type 'multipart/form-data;boundary=----...;charset=UTF-8' not supported 不支持 Spring Boot 内容类型 'multipart/form-data;boundary=------------------------#;charset=UTF-8' - Spring Boot Content type 'multipart/form-data;boundary=--------------------------#;charset=UTF-8' not supported
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM