最近工作中和其他项目组的对接过程中,涉及到了HTTP 的GET 和 POST操作。C++中ATL有相关的东西,但是我不太愿意为了这个简单的功能引入太多没必要的框架或者库。
因此自己动手在项目中,用ACE框架简单封装了一个静态类,以实现GET和POST操作。
代码由于信息安全无法上传,先将GET和POST操作的HTTP协议头格式记录如下,以方便使用。
GET提交HTTP头:
GET /TestWeb/index.jsp HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Accept-Language: zh-CN
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
Accept-Encoding: gzip, deflate
Host: localhost:8080
DNT: 1
Connection: Keep-Alive
POST提交HTTP头:
POST /TestWeb/index.jsp HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Accept-Language: zh-CN
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
Accept-Encoding: gzip, deflate
Host: localhost:8080
Content-Length: 26
Connection: Keep-Alive
username=asdfadsf&yemian=0
自己根据实际情况修改其中的值和部分字段,socket简单实现一下就可以了。