美文网首页
表单提交上传文件

表单提交上传文件

作者: 皮皮鸡很皮 | 来源:发表于2019-05-14 10:09 被阅读0次

    the request was rejected because no multipart boundary was found

    org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found
        org.apache.tomcat.util.http.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:840)
        org.apache.tomcat.util.http.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:259)
        org.apache.tomcat.util.http.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:283)
        org.apache.catalina.connector.Request.parseParts(Request.java:2811)
        org.apache.catalina.connector.Request.getParts(Request.java:2729)
        org.apache.catalina.connector.RequestFacade.getParts(RequestFacade.java:1075)
    

    问题: form表单提交,包含了文件上传 和普通的key value 字段, 报了上诉的错误。

    POST /xc/dispatcher HTTP/1.1
    Host: localhost:8080
    Cache-Control: no-cache
    Postman-Token: 15b6f371-5cd5-ed7a-8a7e-063bc442f581
    Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
    
    ------WebKitFormBoundary7MA4YWxkTrZu0gW
    Content-Disposition: form-data; name="request"
    
    vU9OZmOQo5fYC6i26WbVO3UsK6wc6eYBhU9EjJsauLxQMHezbkgUUk556Ft+pp3cDeiUM2BcIf7N4O0oqabg72DFfVuCyMgak0MIynovhnJlyMeDna9d48CmiKyWyuRQTrrg0fSdUQIfNwCNlrq0kipKLmsMbPf8fV6sQbdW6QL4TEiKfMfh1M5qEjRAPo1XqDEdBs/cg0OYosC0LLHGVQfY9AmW8HJncSGwPLnq7yoaO4aWnnIH3+SW1z5AMP6wWCjhI9CUECDdYTYj3Ot3fIH14B+lukhs6pMJWeYMgBFHncmKHVzbHw8akOGNg0NdOmJVjRe+zGrc0h6MdhCL92IRfbdGRqH3jJUari5adsNh3HhfBRGNlG+S/zjNCyd0H/Ipl448FFNxYE8wmOaMnbdcponY/TUzNsdUw5R16cJNv/YIGTf5AdezbDcIILYGgvsiwSU2LDazbmGQng284OH1+0TATOcIEhJE/7JlMQ8iykwfP/v9wFp6QmyiqJ/TloRwn5EVqCqPStXA6FYydpQr0HIQ5dRojoPj3IM1FkI=
    ------WebKitFormBoundary7MA4YWxkTrZu0gW
    Content-Disposition: form-data; name="file"; filename="1.png"
    Content-Type: image/png
    
    
    ------WebKitFormBoundary7MA4YWxkTrZu0gW--
    

    去除Content-Type后:
    Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

    手动设置后header:
    Content-Type: multipart/form-data

    解决方案:
    request header中不需要手动添加Content-Type(multipart/form-data),故去除header中Content-Type即可.

    相关文章

      网友评论

          本文标题:表单提交上传文件

          本文链接:https://www.haomeiwen.com/subject/ggmjaqtx.html