如果我使用以下格式设置html页面:
<html>
<body>
<form action="upload_file.php"
method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我可以将文件上传到upload_file.php,我可以使用php脚本处理它.
出于测试目的,我需要通过Putty会话使用原始HTTP来做同样的事情.
我可以这样做一个正常的POST(只发送文本数据):
POST /test_post.php HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 11
name=myname
Run Code Online (Sandbox Code Playgroud)
如何以这种方式发送文件?
Azi*_*ikh 14
您必须使用multipart内容类型并将文件数据编码为十六进制/二进制
在telnet中尝试以下操作:
POST /the_url HTTP/1.1
User-Agent: Mozilla
Host: www.example.com
Content-Length: xxxx
Content-Type: multipart/form-data; boundary=--------------------31063722920652
------------------------------31063722920652
Content-Disposition: form-data; name="a"
value_for_a
------------------------------31063722920652
Content-Disposition: form-data; name="b"
value_for_b
------------------------------31063722920652
Content-Disposition: form-data; name="c"; filename="myfile.txt"
Content-Type: text/plain
This is a test
and more
-----------------------------31063722920652
Content-Disposition: form-data; name="submit"
Submit
-----------------------------31063722920652--
Run Code Online (Sandbox Code Playgroud)
请记住,字段名称与其数据之间需要额外的换行符.另外,更新Content-Length值.
使用 netcat 打开端口并保存传入请求:
nc -l -p 1090 > income-http.txt
Run Code Online (Sandbox Code Playgroud)
然后修改您的表单以将数据发送到 netcat:
<form action="http://localhost:1090/upload_file.php"
method="post" enctype="multipart/form-data">
Run Code Online (Sandbox Code Playgroud)
从浏览器提交表单。您可以在文件中找到包含文件内容的完整原始请求income-http.txt。
保存income-http.txt是一项一次性活动。稍后您可以随时发送保存的请求。请注意,您应该编辑Host:保存的 txt 中的标题。
| 归档时间: |
|
| 查看次数: |
29546 次 |
| 最近记录: |