将文件发布到 Jenkins 失败
我正在尝试通过 multipart/form-data 从 Python 将文件发布到 Jenkins。请求正文如下所示:
--===============1849003312==
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64
Content-Disposition: file; name="file0"; filename="meta.xml"
PHhtbD4NCjwveG1sPg0K
--===============1849003312==--
这会导致 Jenkins 在其末尾引发异常,但其中最相关的部分如下:
Exception: <br>Stacktrace: <pre>org.apache.commons.fileupload.FileUploadException: Stream ended unexpectedly
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:381)
at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
at org.kohsuke.stapler.RequestImpl.parseMultipartFormData(RequestImpl.java:767)
at org.kohsuke.stapler.RequestImpl.getSubmittedForm(RequestImpl.java:782)
我的 POST 请求出了什么问题?
编辑: 请求标头如下:
Content-Type:
multipart/form-data; boundary="===============1849003312=="
MIME-Version:
1.0
I'm trying to POST a file to Jenkins from Python, via multipart/form-data. The request body looks like this:
--===============1849003312==
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64
Content-Disposition: file; name="file0"; filename="meta.xml"
PHhtbD4NCjwveG1sPg0K
--===============1849003312==--
This causes Jenkins to raise an exception on its end however, the most relevant bits of which follow:
Exception: <br>Stacktrace: <pre>org.apache.commons.fileupload.FileUploadException: Stream ended unexpectedly
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:381)
at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
at org.kohsuke.stapler.RequestImpl.parseMultipartFormData(RequestImpl.java:767)
at org.kohsuke.stapler.RequestImpl.getSubmittedForm(RequestImpl.java:782)
What's wrong with my POST request?
EDIT:
The request headers are as follows:
Content-Type:
multipart/form-data; boundary="===============1849003312=="
MIME-Version:
1.0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为
Content-Disposition: file;
应该替换为Content-Disposition: Attachment;
。 FileUploadBase 未提及“文件”,并且 RFC 2183 未将“文件”列为内容处置的值。I believe the
Content-Disposition: file;
should be replaced withContent-Disposition: attachment;
. The source code of FileUploadBase does not mention "file", and RFC 2183 does not list "file" as a value for content-disposition.