#7 Borisek
program Project2;
2{$APPTYPE CONSOLE}
3uses
4 SysUtils, httpsend, Classes, blcksock;
5
6var
7 sl: TStringList;
8
9type
10 TStatusWriter = class
11 private
12 fiProgress: Int64;
13 foHttp: THTTPSend;
14 public
15 constructor Create(HTTP: THTTPSend);
16 procedure Status (Sender: TObject; Reason: THookSocketReason;
17 const Value: String);
18 end;
19
20constructor TStatusWriter.Create(HTTP: THTTPSend);
21begin
22 foHttp := HTTP;
23end;
24
25procedure TStatusWriter.Status (Sender: TObject; Reason: THookSocketReason;
26 const Value: String);
27begin
28 case Reason of
29 HR_Connect:
30 writeln('Connect!');
31 HR_SocketClose:
32 writeln('Close!');
33
34 HR_SocketCreate:
35 fiProgress := 0;
36 HR_ReadCount:
37 begin
38 inc(fiProgress, StrToIntDef(Value, 0));
39 writeln('Read:', fiProgress);
40 writeln('Size:', foHttp.Downloadsize);
Application.ProcessMessages;
41 end;
42 end;
43end;
44
45
46function bHttpGetText(const URL: string; const Response: TStrings): Boolean;
47var
48 HTTP: THTTPSend;
49 oWriter: TStatusWriter;
50begin
51 HTTP := THTTPSend.Create;
52 oWriter := TStatusWriter.Create(HTTP);
53 try
54{ HTTP.ProxyHost := 'host';
55 HTTP.ProxyPass := 'password';
56 HTTP.ProxyPort := port;
57 HTTP.ProxyUser := 'user'}
58 HTTP.Protocol := '1.1';
59// HTTP.UserAgent := 'Mozilla/5.0 (Windows; U; Windows NT 5.0; rv:1.7.6) Gecko/20050321 Firefox/1.0.2';
60
61 HTTP.Sock.OnStatus := oWriter.Status;
62 Result := HTTP.HTTPMethod('GET', URL);
63 if Result then
64 Response.LoadFromStream(HTTP.Document);
65 finally
66 HTTP.Free;
67 oWriter.Free;
68 end;
69end;
70
71
72begin
73 sl := TStringList.Create;
74 try
75{ HttpGetText('http://www.google.cz/', sl);
76 writeln(sl.Text); }
77
78 bHttpGetText('http://www.idnes.cz/', sl);
79// writeln(sl.Text);
80 writeln('Delka:'+IntToStr(Length(sl.Text)));
81
82
83 finally
84 FreeAndNil(sl);
85 end;
86end.