通过 C++ 使用 HTTP POST 上传文件失败
我收到 HTTP/1.1 500 Internal Server Error 我想做的是我通过套接字发送一个 http 数据包 http 数据包包含数据,这里的文件是我的数据包
POST /my/service HTTP/1.0
Host: myhostname.com
Accept: */*
Content-Type: multipart/form-data; boundary=----acbn1234
Content-Length: 62
------acbn1234
Content-Disposition: form-data; name="segment"
name
------acbn1234
Content-Disposition: form-data; name="segid"
abc123
------acbn1234
Content-Disposition: form-data; name="segname"
segment1
------acbn1234
Content-Disposition: form-data; name="txtfile"; filename="textfile.txt"
Content-Type: text/plain
segment information this the data in the file
------acbn1234--
服务器端是 apache tomcat 服务器在控制台上显示
SEVERE: Servlet.service() for servlet ssp-dispatcher threw exception
org.apache.commons.fileupload.MultipartStream$MalformedStreamException: Stream ended unexpectedly
at org.apache.commons.fileupload.MultipartStream.readHeaders(MultipartStream.java:538)
at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.findNextItem(FileUploadBase.java:999)
at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.hasNext(FileUploadBase.java:1063)
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:357)
at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
at org.springframework.web.multipart.commons.CommonsMultipartResolver.parseRequest(CommonsMultipartResolver.java:155)
at org.springframework.web.multipart.commons.CommonsMultipartResolver.resolveMultipart(CommonsMultipartResolver.java:138)
at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:887)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:750)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:585)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:877)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:594)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1675)
at java.lang.Thread.run(Unknown Source)
异常错了,我的 HTTP 数据包正常,服务器没有显示错误请求,即 404,我认为它显示内部服务器错误 500。?
I am getting HTTP/1.1 500 Internal Server Error what i am trying to do is i am sending a http packet though socket the http packet contains data and a file here is my packet
POST /my/service HTTP/1.0
Host: myhostname.com
Accept: */*
Content-Type: multipart/form-data; boundary=----acbn1234
Content-Length: 62
------acbn1234
Content-Disposition: form-data; name="segment"
name
------acbn1234
Content-Disposition: form-data; name="segid"
abc123
------acbn1234
Content-Disposition: form-data; name="segname"
segment1
------acbn1234
Content-Disposition: form-data; name="txtfile"; filename="textfile.txt"
Content-Type: text/plain
segment information this the data in the file
------acbn1234--
the server side is apache tomcat server shows exception on console
SEVERE: Servlet.service() for servlet ssp-dispatcher threw exception
org.apache.commons.fileupload.MultipartStream$MalformedStreamException: Stream ended unexpectedly
at org.apache.commons.fileupload.MultipartStream.readHeaders(MultipartStream.java:538)
at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.findNextItem(FileUploadBase.java:999)
at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.hasNext(FileUploadBase.java:1063)
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:357)
at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
at org.springframework.web.multipart.commons.CommonsMultipartResolver.parseRequest(CommonsMultipartResolver.java:155)
at org.springframework.web.multipart.commons.CommonsMultipartResolver.resolveMultipart(CommonsMultipartResolver.java:138)
at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:887)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:750)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:585)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:877)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:594)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1675)
at java.lang.Thread.run(Unknown Source)
where i am wrong my HTTP packet is ok the server doesn't shows bad request i.e 404 i think it shows internal server error 500. ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的内容长度标头不正确。您的数据约为 400 字节,而不是 62。
Your content-length header is incorrect. Your data is about 400 bytes, not 62.