gpt4 book ai didi

Spring MVC框架: MultipartResolver with PUT method

转载 作者:行者123 更新时间:2023-12-04 05:38:55 25 4
gpt4 key购买 nike

我正在开发一个带有框架3.2.3的spring mvc应用程序

在我的应用程序中,我使用StandardServletMultipartResolver处理Multipart,但是使用apache commons-fileupload 1.3,情况是一样的。

我想知道为什么isMultipart方法的实现只考虑POST方法,而不考虑PUT方法。如果要更新实体和相关文件,则必须使用POST进行。

查看org.springframework.web.multipart.support.Standard ServletMultipartResolver:

public boolean isMultipart(HttpServletRequest request) {
// Same check as in Commons FileUpload...
if (!"post".equals(request.getMethod().toLowerCase()) ) {
return false;
}
String contentType = request.getContentType();
return (contentType != null && contentType.toLowerCase().startsWith("multipart/"));
}

而在org.apache.commons.fileupload.servlet.ServletFileU pload中,我有:
public static final boolean isMultipartContent(HttpServletRequest request) {
if (!POST_METHOD.equalsIgnoreCase(request.getMethod() )) {
return false;
}
return FileUploadBase.isMultipartContent(new ServletRequestContext(request));
}

并不是至关重要的事情,实际上只是使用POST方法对PUT起作用。。但是我想理解为什么不考虑PUT!

谢谢你的回复
马可

最佳答案

RFC说

http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6

The URI in a POST request identifies the resource that will handle the enclosed entity. That resource might be a data-accepting process, a gateway to some other protocol, or a separate entity that accepts annotations. In contrast, the URI in a PUT request identifies the entity enclosed with the request -- the user agent knows what URI is intended and the server MUST NOT attempt to apply the request to some other resource.



因此,PUT请求代表单个资源。
但是,多部分意味着在单个主体中具有多个资源。

http://www.w3.org/Protocols/rfc1341/7_2_Multipart.html

In the case of multiple part messages, in which one or more different sets of data are combined in a single body, a "multipart" Content-Type field must appear in the entity's header. The body must then contain one or more "body parts," each preceded by an encapsulation boundary, and the last one followed by a closing boundary.



因此,根据PUT的语义,请求与多部分数据不匹配。
与POST匹配,因为POST请求的请求URI是“封闭实体的处理程序”。

关于Spring MVC框架: MultipartResolver with PUT method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20373912/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com