简体   繁体   English

我可以获得没有标头的HttpServletRequest请求体吗?

[英]Can I get the HttpServletRequest request body without headers?

When a file is submitted to my server using a multipart/form-data POST, is it possible to retrieve only the content of the file from the HttpServletRequest object? 当使用multipart / form-data POST将文件提交到我的服务器时,是否可以从HttpServletRequest对象中仅检索文件的内容? The request.getInputStream() shows some headers included at the beginning and then ------WebKitFormBoundary... at the end. request.getInputStream()显示开头包含的一些头文件,然后是------WebKitFormBoundary...最后。

Can I get just the file data without having to parse the input stream and extract it? 我是否可以只获取文件数据而无需解析输入流并将其解压缩?

You could annotate your servlet with @MultipartConfig , then you can use HttpServletRequest#getParts() to get the individual parts. 您可以使用@MultipartConfig注释您的servlet,然后您可以使用HttpServletRequest#getParts()来获取各个部分。

This is available starting from Servlet 3.0. 这是从Servlet 3.0开始提供的。 If for some reason you're stuck on an older version of Java Servlets, you may choose to use Apache Commons File Upload . 如果由于某种原因你被困在旧版本的Java Servlets上,你可以选择使用Apache Commons File Upload

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

相关问题 从 HttpServletRequest 获取 POST 请求体 - Get the POST request body from HttpServletRequest Spring Rest-设置没有请求主体的标题 - Spring Rest - set headers without request body 如何从ServletContext获取HttpServletRequest? - How can I get HttpServletRequest from ServletContext? 如何在HttpSessionListener中获取HttpServletRequest? - How can I get HttpServletRequest when in an HttpSessionListener? 如何在不干扰主要逻辑的情况下安全地记录来自 HttpServletRequest 的请求正文? - How to safely log request body from HttpServletRequest without interferring main logic? 使用 HttpServletRequest 获取请求发件人的 URL - Get URL of the request sender with HttpServletRequest 如何获取此 GET 请求的 json 正文? - How can i get the json body of this GET request? 如何像使用HttpServletRequest一样从Spring MVC中的org.springframework.web.context.request.WebRequest中获取requestUrl? - How can I get the requestUrl from org.springframework.web.context.request.WebRequest in Spring MVC like we do using HttpServletRequest? 使用 ContentCachingRequestWrapper 缓存 HttpServletRequest object 后,如何读取请求正文? - How am I able to read the request body after caching the HttpServletRequest object using ContentCachingRequestWrapper? Unirest标头要求主体 - Unirest Headers Request Body
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM