C/C++程序实现通过http代理访问网页内容
来源:互联网 发布:淘宝拍了不发货怎么办 编辑:程序博客网 时间:2024/05/17 05:56
公司通过代理上网,C程序直接通过发http请求不能获取网页内容,故实现了下通过代理访问http网页的一个测试程序。
程序很简单,有几个重点
先通过socket直接连接代理服务器
向代理服务器发送HTTP的CONNECT标头,格式为CONNECT www.baidu.com:80 HTTP/1.0\r\nProxy-Authorization: Basic %s\r\n\r\n
其中%s处替换为user:passwd的base64编码
鉴权通过后 send请求就ok,注意此处和不用代理的区别是 GET后面的地址要http://www.baidu.com 而不能是www.baidu.com
这是个测试程序,目的只是说明实现过程,我测试的可以收到返回报文,也有不完善的地方,比如接收不全。
代码如下:
测试结果:
[@dev1 myfile]$ ./proxy_test
-=-=-=-=-=-=-=We have connect the proxy ok!!!!-=-=-=-=-=-=-=
=======test:1111132%--=====YdlsdfdiaDp6YmgyNDI3MDY1JQ==-=-=-=-=-=wait for recv-=-=-=-=-=
recv=HTTP/1.0 200 Connection established
recv2=HTTP/1.1 200 OK
Date: Wed, 06 Nov 2013 10:15:13 GMT
Server: Apache
P3P: CP=" OTI DSP COR IVA OUR IND COM "
P3P: CP=" OTI DSP COR IVA OUR IND COM "
Set-Cookie: BAIDUID=8F0C54DC13B905C0FA9EFD43B9D053C1:FG=1; expires=Thu, 06-Nov-14 10:15:13 GMT; max-age=31536000; path=/; domain=.baidu.com; version=1
Set-Cookie: BAIDUID=8F0C54DC13B905C09E3548EFD4211EBA:FG=1; expires=Thu, 06-Nov-14 10:15:13 GMT; max-age=31536000; path=/; domain=.baidu.com; version=1
Last-Modified: Mon, 31 Dec 2012 10:42:36 GMT
ETag: "1cdb-4d223abde3f00"
Accept-Ranges: bytes
Content-Length: 7387
Cache-Control: max-age=1
Expires: Wed, 06 Nov 2013 10:15:14 GMT
Vary: Accept-Encoding,User-Agent
Connection: Close
Content-Type: text/html
<!doctype html><html><head><meta http-equiv="Content-Type" content="text/html;charset=gb2312"><title>百度一下,你就知道 </title><style>html{overflow-y:auto}body{font:12px arial;text-align:center;background:#fff}body,p,form,ul{margin:0;padding:0}body,form,#fm{position:relative}td{text-align:left}img{border:0}a{color:#00c}a:active{color:#f60}#u{padding:7px 10px 3px 0;text-align:right}#m{width:680px;margin:0 auto}#nv{font-size:16px;margin:0 0 4px;text-align:left;text-indent:117px}#nv a,#nv b,.btn,#lk{font-size:14px}#fm{padding-left:90px;text-align:left}#kw{width:404px;height:22px;padding:4px 7px;padding:6px 7px 2px\9;font:16px arial;background:url(http://www.baidu.com/img/i-1.0.0.png) no-repeat -304px 0;_background-attachment:fi[@dev1 myfile]$
- C/C++程序实现通过http代理访问网页内容
- C/C++程序实现通过http代理访问网页内容
- [Winhttp]_[C/C++]_[使用win32 SDK的Windows HTTP Services(WinHTTP)通过代理下载网页]
- java通过代理访问http
- Http代理篡改网页,html污染,http代理服务器污染html,c#http代理
- 获取网页内容 C和php通过socket进行通信
- C实现通过sock发送http请求
- C#(ASP.NET) 下载数据 C#实现通过程序自动抓取远程Web网页信息
- C# webBrowser 通过代理访问网页
- linux c下的一个简易http代理程序
- C#HTTP代理的实现之注册表实现
- ssh通过http代理访问服务器
- C语言实现http get请求程序
- C#WebRequest设置代理访问
- Java程序通过代理访问网络
- Java程序通过代理访问网络
- c-lodop打印网页内容
- [乐意黎原创] 通过Apache反向代理实现多个http/https访问NodeJS服务
- django 1.9.7学习笔记(1)
- 如何更改通达OA附件的存储目录
- 多线程同步之事件 -- 2个线程交替打印数字
- Robot FrameWork自动测试之入门范例
- 拯救2K屏手机!修改屏幕分辨率省电教程
- C/C++程序实现通过http代理访问网页内容
- Ubuntu每次打开终端出现错误提示的解决方法
- 高性能计算中心汇总(原创)
- [51nod 1766]树上的最远点对
- CSS Secret——Visual Effect
- 欢迎使用CSDN-markdown编辑器
- 全能安卓手机修改器,能使你的手机变成无数款不同的手机
- scikit learn 模块 调参 pipeline+girdsearch
- 日夜间模式