gip*_*ani 8 spring multipartform-data spring-mvc apache-commons-fileupload
我正在使用框架3.2.3.RELEASE开发一个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));
}
不是一件至关重要的事情,事实上只是使用PUT工作的POST方法.但我想承认为什么PUT不被考虑在内!
谢谢你回复Marco
小智 13
RFC说 
http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6
POST请求中的URI标识将处理所包含实体的资源.该资源可能是数据接受过程,某些其他协议的网关或接受注释的单独实体.相反,PUT请求中的URI标识请求附带的实体 - 用户代理知道URI的用途,并且服务器不得尝试将请求应用于其他资源.
因此PUT请求代表单个资源.
但是多部分意味着单个机构中的多个资源.
http://www.w3.org/Protocols/rfc1341/7_2_Multipart.html
在多部分消息的情况下,其中一个或多个不同的数据集合在一个主体中,"多部分"内容类型字段必须出现在实体的头部中.然后,主体必须包含一个或多个"主体部分",每个主体部分前面都有一个封装边界,最后一个后面是一个封闭边界.
因此,PUT请求的语义与多部分数据不匹配.POST是匹配的,因为POST请求的请求URI是"封闭实体的处理程序".
| 归档时间: | 
 | 
| 查看次数: | 3456 次 | 
| 最近记录: |