IDHTTP的基本用法
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
一、IDHTTP的基本用法IDHttp和WebBrowser一样,都可以实现抓取远端网页的功能,但是http方式更快、更节约资源,缺点是需要手动维护cook,连接等IDHttp的创建,需要引入IDHttpprocedure InitHttp();begin http := TIdHTTP.Create(nil); http.ReadTimeout := 30000; http.OnRedirect := OnRedirect; http.Request.Accept := 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*'; http.Request.AcceptLanguage := 'zh-cn'; http.Request.ContentType := 'application/x-www-form-urlencoded'; http.Request.UserAgent := 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 1.1.4322)'; http.ProxyParams.ProxyServer := '代理服务器地址'; http.ProxyParams.ProxyPort := '代理服务器端口';end;二、如何取得服务端返回的cookie信息,并添加到http的request对象中procedure Setcookie;var i: Integer; tmp, cookie: String;begin cookie := ''; for i := 0 to http.Response.RawHeaders.Count - 1 do begin tmp := http.Response.RawHeaders[i]; if pos('set-cookie: ', LowerCase(tmp)) = 0 then Continue; tmp := Trim(Copy(tmp, Pos('Set-cookie: ', tmp) + Length('Set-cookie: '), Length(tmp))); tmp := Trim(Copy(tmp, 0, Pos(';', tmp) - 1)); if cookie = '' then cookie := tmp else cookie := cookie + '; ' + tmp;end;if cookie <> '' thenbegin for i := 0 to http.Request.RawHeaders.Count - 1 do begin tmp := http.Request.RawHeaders[i]; if Pos('cookie', LowerCase(tmp)) = 0 then Continue; http.Request.RawHeaders.Delete(i); Break; end; http.Request.RawHeaders.Add('cookie: ' + cookie);end;end;三、如何取得网页中的所有连接,对代码做修改你也可以实现查找所有图片等等function GetURLList(Data: String): TStringList;vari: Integer;List: TStringList;tmp: String;function Split(Data, Node: String): TStringList; var Count, i, j: Integer; function GetFieldCount(Data, Node: String): Integer; var i: Integer; begin Result := -1; i := Pos(Node, Data); if i = 0 then Exit; Result := 0; while i <> 0 do begin Inc(Result); Delete(Data, 1, i + Length(Node) - 1); i := Pos(Node, Data); end; end; begin Result := TStringList.Create;Count := GetFieldCount(Data, Node);for i := 0 to Count - 1 dobegin j := Pos(Node, Data); Result.Add(Copy(Data, 1, j - 1)); Delete(Data, 1, j + Length(Node) - 1);end;Result.Add(Data);end;beginResult := TStringList.Create;try List := split(Data, 'href='); for i := 1 to List.Count - 1 do begin tmp := List[i]; tmp := Copy(tmp, 0, Pos('</a>', tmp) - 1); tmp := Copy(tmp, 0, Pos('>', tmp) - 1); if Pos(' ', tmp) <> 0 then tmp := Copy(tmp, 0, Pos(' ', tmp) - 1); tmp := Q_ReplaceStr(tmp, Char(34), ''); tmp := Q_ReplaceStr(tmp, Char(39), ''); if not Compare(CI.Key, tmp) then Continue; if Copy(tmp, 1, 7) <> 'http://' then begin if Copy(tmp, 1, 1) = '.' then tmp := StringReplace(tmp, '.', '', []); if Copy(tmp, 1, 1) = '.' then tmp := StringReplace(tmp, '.', '', []); try tmp := 'http://' + http.URL.Host + ':' + http.URL.Port + http.URL.Path + tmp; except end; end; if Result.IndexOf(tmp) <> -1 then Continue; Result.Add(tmp); end; FreeAndNil(List);exceptend;end;四、如何模拟http的get方法打开一个网页function GetMethod(http: TIDhttp; URL: String; Max: Integer): String;varRespData: TStringStream;beginRespData := TStringStream.Create('');try try Http.Get(URL, RespData); Http.Request.Referer := URL; Result := RespData.DataString; except Dec(Max); if Max = 0 then begin Result := ''; Exit; end; Result := GetMethod(http, URL, Max); end;finally FreeAndNil(RespData);end;end;五、如何模拟http的post方法提交一个网页function PostMethod(URL, Data: String; max: Integer): String;varPostData, RespData: TStringStream;beginRespData := TStringStream.Create('');PostData := TStringStream.Create(Data);try try if http = nil then Exit; Http.Post(URL, PostData, RespData); Result := RespData.DataString; http.Request.Referer := URL; except Dec(Max); if Max = 0 then begin Result := ''; Exit; end; Result := PostMethod(URL, Data, Max); end;finally http.Disconnect; FreeAndNil(RespData); FreeAndNil(PostData);end;end;六、伪造sessionvarMy_Cookie,tmpcookie:string;beginaIdHttp.Get('http://www.huochepiao.net/');tmpcookie:=aIdHttp.Request.CustomHeaders.Values['Set-Cookie']; if Pos(';',tmpcookie)>0 then My_Cookie:=LeftBStr(tmpcookie,Pos(';',tmpcookie)-1)else My_Cookie:= tmpcookie;//aIdHTTP.Request.CustomHeaders.Clear;aIdHTTP.Request.CustomHeaders.Add('Cookie:'+My_COOKIE);end; |
IDHTTP的基本用法的更多相关文章
- IDHttp的基本用法(转)
一.IDHTTP的基本用法 IDHttp和WebBrowser一样,都可以实现抓取远端网页的功能,但是http方式更快.更节约资源,缺点是需要手动维护cook,连接等 IDHttp的创建,需要引入ID ...
- Delphi的IDHTTP的基本用法
一.IDHTTP的基本用法 IDHttp和WebBrowser一样,都可以实现抓取远端网页的功能,但是http方式更快.更节约资源,缺点是需要手动维护cook,连接等 IDHttp的创建,需要引入ID ...
- Delphi IDHTTP用法详解(六种用法)
一.IDHTTP的基本用法 IDHttp和WebBrowser一样,都可以实现抓取远端网页的功能,但是http方式更快.更节约资源,缺点是需要手动维护cook,连接等 IDHttp的创建,需要引入ID ...
- Delphi IDHTTP用法详解
一.IDHTTP的基本用法 IDHttp和WebBrowser一样,都可以实现抓取远端网页的功能,但是http方式更快.更节约资源,缺点是需要手动维护cook,连接等 IDHttp的创建,需要引入 ...
- IDHTTP用法详解 good
一.IDHTTP的基本用法 IDHttp和WebBrowser一样,都可以实现抓取远端网页的功能,但是http方式更快.更节约资源,缺点是需要手动维护cook,连接等 IDHttp的创建,需要引入ID ...
- IdHttp 资料
http://blog.csdn.net/delphizhou/article/details/3085704 IdHttp 资料 网上找了些不过很不好找.今天找了些收藏在一起.以便他人查阅, idh ...
- IDHTTP
Delphi IDHTTP用法详解 一.IDHTTP的基本用法 IDHttp和WebBrowser一样,都可以实现抓取远端网页的功能,但是http方式更快.更节约资源,缺点是需要手动维护cook,连接 ...
- delphi idhttp 实战用法(TIdhttpEx)
以delphi XE8 自带indy(10.5.8.0)组件为例,分享实战中遇到的问题及解决方法. TIdHttpEx 用法实例01[多线程获取网页](包含完整源码) 实例02(如何Post参数,如何 ...
- INDY idhttp Post用法
http://www.cnblogs.com/tk-del/archive/2013/05/10/3071541.html function Post(AURL: string; ASource: T ...
随机推荐
- 02. pt-archiver
pt-archiver \--source h=192.168.100.101,P=3306,u=admin,p='admin',D=db01,t=t01 \--dest h=192.168.100. ...
- libpcap 库使用(二)
参考资料: http://www.tcpdump.org/manpages/pcap.3pcap.html 分类介绍了该lib的函数 Opening a capture handle for read ...
- python爬虫之urlError异常处理
1.URLError URLError产生的原因: (1)网络无连接,即本机无法上网 (2)连接不到特定的服务器 (3)服务器不存在 import urllib.request import urll ...
- Java学习笔记:多线程(一)
Java中线程的五种状态: 新建状态(New) 就绪状态(Runnable) 运行状态(Running) 阻塞状态(Blocked) 凋亡状态(Dead) 其中阻塞状态(Blocked)又分为三种: ...
- Flex 排序 SortField and Sort
部分代码 var arrayOfCat:ArrayCollection=outerDocument.getCagegory(); // 需要排序的数组 //创建SortField对象 var so ...
- Python10/22--面向对象编程/类与对象/init函数
类: 语法: class关键字 类名# 类名规范 大写开头 驼峰命名法class SHOldboyStudent: # 描述该类对象的特征 school = "上海Oldboy" ...
- Svn项目管理工具
1 svn介绍 1.1 项目管理中的版本控制问题 通常软件开发由多人协作开发,如果对代码文件.配置文件.文档等没有进行版本控制,将会出现很多问题: 备份多个版本,占用磁盘空间大 解 ...
- 2019.02.06 bzoj2987: Earthquake(类欧几里得)
传送门 题意简述:求满足ax+by+c≤0ax+by+c\le0ax+by+c≤0的二元组(x,y)(x,y)(x,y)对数. 思路: 类欧几里得算法模板题. 把式子变化一下变成:求满足0≤y≤−ax ...
- 2018.12.14 codeforces 922E. Birds(分组背包)
传送门 蒟蒻净做些水题还请大佬见谅 没错这又是个一眼的分组背包. 题意简述:有n棵树,每只树上有aia_iai只鸟,第iii棵树买一只鸟要花cic_ici的钱,每买一只鸟可以奖励bbb块钱,从一棵 ...
- oracle创建视图(view)
视图:是基于一个表或多个表或视图的逻辑表,本身不包含数据,通过它可以对表里面的数据进行查询和修改.视图基于的表称为基表,Oracle的数据库对象分为五种:表,视图,序列,索引和同义词. 视图是存储在数 ...