Socket实现发送Http请求上传文件

最近在实现发送反馈的功能,需要自己封装实现Http上传,首先需要知道上传表单数据的格式,下面是我获取的请求格式

Remote Address:127.0.0.1:80
Request URL:http://127.0.0.1/test/welcome.php
Request Method:POST
Status Code:200 OK
Response Headers
view source
Connection:Keep-Alive
Content-Length:618
Content-Type:text/html
Date:Fri, 04 Aug 2017 03:10:32 GMT
Keep-Alive:timeout=5, max=100
Server:Apache/2.4.23 (Win32) OpenSSL/1.0.2j PHP/5.4.45
X-Powered-By:PHP/5.4.45
Request Headers
view source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Content-Length:591892
Content-Type:multipart/form-data; boundary=----WebKitFormBoundary89hoWoA4ABt14mYg
Host:127.0.0.1
Origin:http://127.0.0.1
Referer:http://127.0.0.1/test/form.html
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36
Request Payload
------WebKitFormBoundary89hoWoA4ABt14mYg
Content-Disposition: form-data; name="comment"


无赖,无赖,江湖要我背对着你,啊,狂风呀,暴雨,狂风啊,暴雨,别得意,有什么了不起,我就此发誓,挥刀杀到天边去
------WebKitFormBoundary89hoWoA4ABt14mYg
Content-Disposition: form-data; name="name"


xinxin
------WebKitFormBoundary89hoWoA4ABt14mYg
Content-Disposition: form-data; name="email"


13234234@qq.com
------WebKitFormBoundary89hoWoA4ABt14mYg
Content-Disposition: form-data; name="file"; filename="汇编记录.doc"
Content-Type: application/msword


------WebKitFormBoundary89hoWoA4ABt14mYg--


上传文件到服务器最主要的是按上面的请求格式封装好,然后再去发送请求数据

请求头的格式:

POST /test/upload.php HTTP/1.1
Host: 127.0.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://127.0.0.1/test/form.html
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36
Content-Type: multipart/form-data; boundary=----AOMEIBackupForBoundary8oZtvmhb0OlCkGLo
Content-Length: 321530605


实例代码下载地址:

http://download.csdn.net/download/slfkj/9929422

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值