php - PHP文件传输错误3
问题描述
我正在开发一个向我的网页发送“自制”HTTP 传输的应用程序。
"POST /file.php HTTP/1.0\r\n"
"Host: xxxx.com\r\n"
"Content-type: multipart/form-data; boundary=\"Abcdefghijklmnopqrstuvwxyz\"\r\n"
"Content-Length:163\r\n"
"\r\n"
"--Abcdefghijklmnopqrstuvwxyz\r\n"
"Content-Disposition: form-data; name=\"file\"; filename=\"myfile.txt\"; content-Type:text/plain\r\n"
"\r\n"
"test"
"--Abcdefghijklmnopqrstuvwxyz--\r\n"
"\r\n"
这是我的 HTTP POST 请求。看起来不错,但是当我执行请求并得到响应时,PHP 脚本文件指示文件上出现错误:“3”。意思是“UPLOAD_ERR_PARTIAL”,但我不知道为什么它表示这样的消息。有效负载长度与 Content-Length 值匹配。
你可以帮帮我吗 ?谢谢你。
解决方案
The problem with your POST request is one missing CRLF in the boundary syntax.
The multipart/form-data is defined in RFC7578 and the boundary syntax is described in Section 4.1 as follows:
As with other multipart types, the parts are delimited with a boundary delimiter, constructed using CRLF, "--", and the value of the "boundary" parameter.
Let's examine your current POST request.
POST /file.php HTTP/1.0
Host: xxxx.com
Content-type: multipart/form-data; boundary="Abcdefghijklmnopqrstuvwxyz"
Content-Length: 163
--Abcdefghijklmnopqrstuvwxyz
Content-Disposition: form-data; name="file"; filename="myfile.txt"; content-Type:text/plain
test--Abcdefghijklmnopqrstuvwxyz--
Based on the specification, the last line should be two lines. There must always be a CRLF and -- before every boundary, so that last line should be like this:
test
--Abcdefghijklmnopqrstuvwxyz--
Therefore the acceptable POST request is this:
POST /file.php HTTP/1.0
Host: xxxx.com
Content-type: multipart/form-data; boundary="Abcdefghijklmnopqrstuvwxyz"
Content-Length: 165
--Abcdefghijklmnopqrstuvwxyz
Content-Disposition: form-data; name="file"; filename="myfile.txt"; content-Type:text/plain
test
--Abcdefghijklmnopqrstuvwxyz--
I'm calling it "acceptable" because there is actually another mistake but it is minor. My server simply ignores the minor mistake and accepts the request without a problem.
推荐阅读
- ios - IOS如何在swift中获取多个String.range(of:string)
- java - Lucene 6.2.1 如何在不知道其名称的情况下获取所有字段名称或搜索所有字段
- javascript - 更改数据源时Angularjs Devextreme组件不刷新
- php - 在特定位置的多维数组中插入新键值
- serverless-framework - 使用 serverless-dotenv-plugin 更正 .env 文件
- linux - 如何删除 2017 年 1 月 1 日之前的所有文件
- jquery - 数组发布为空
- vba - 如何优化下面的VB代码?运行需要花费大量时间,并且 Excel 每次都挂起
- sql - 如何从oracle中的SELECT语句本身中选择自己的表名和列名?
- ios - 如何使用 IOS swift 在 Instagram 和 slack 上分享带有标题的图像?