通过 C++ 使用 HTTP POST 上传文件失败

发布于 2024-12-22 08:40:54 字数 3359 浏览 1 评论 0原文

我收到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何以笙箫默 2024-12-29 08:40:54

您的内容长度标头不正确。您的数据约为 400 字节,而不是 62。

Your content-length header is incorrect. Your data is about 400 bytes, not 62.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文