在 C# 中,我正在开发一个项目,用图像和其他表单数据等自动更新单独的服务器......但是,PHP 服务器没有获取任何 POST 数据,它只获取 header 我不知道为什么。
这是我发送到服务器的内容(所有新行都有 CRLF):
POST /new_reply/1 HTTP/1.1
Host: 192.168.1.104
User-Agent: Update Bot
Cookie: SID=sib5m5lgaq66vfp2nfhpab6ug0;UID=bot
Content-Type: multipart/form-data; boundary=-----xxx
Content-Length: 1903
-----xxx
Content-Disposition: form-data; name="form_sent"
1
-----xxx
Content-Disposition: form-data; name="name"
-----xxx
Content-Disposition: form-data; name="body"
hej fra mig
-----xxx
Content-Disposition: form-data; name="image"; filename="test.jpg"
Content-Type: image/jpeg
(image data)
-----xxx
Content-Disposition: form-data; name="post"
Post
-----xxx--
这是请求的隐藏字符显示图像:
这是页面/new_reply/1 上 $_REQUEST 的 PHP print_r:
Array
(
[reply] => 1
[SID] => sib5m5lgaq66vfp2nfhpab6ug0
[UID] => bot
)
如您所见,所有帖子都未通过...
最佳答案
我很确定 Content-Type
header 中指定的边界是错误的。它应该是这样的:
Content-Type: multipart/form-data; boundary=RANDOM_STRING_BOUNDARY
--RANDOM_STRING_BOUNDARY
Content-Disposition: form-data; name="image_name"
Monkey
--RANDOM_STRING_BOUNDARY
Content-Disposition: form-data; name="photo"; filename="monkey.png"
Content-Type: image/png
[ here would be the png file in binary form ]
--RANDOM_STRING_BOUNDARY--
如您所见,RANDOM_STRING_BOUNDARY 在 Content-Type
header 中指定时没有前置连字符,仅在实际使用它的后续 header 中。此外,最后一个用法附加了两个新的连字符(但您已经知道了)。
关于php - 正在发送 POST header ,但未在服务器上接收到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3176656/