[英]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.