Skip to content

Commit b45705d

Browse files
committed
1 parent 49c0898 commit b45705d

File tree

5 files changed

+74
-87
lines changed

5 files changed

+74
-87
lines changed

Examples/Easy_Http/AplusB_Get/f_Main.pas

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ procedure TfmMain.btAddClick(Sender: TObject);
4141
curl := CurlGet;
4242
stream := TRawByteStream.Create;
4343

44-
curl.SetUserAgent(FirefoxUserAgent);
45-
curl.SetUrl(CurlGetBuilder(edUrl.Text)
44+
curl.SetUserAgent(FirefoxUserAgent)
45+
.SetUrl(CurlGetBuilder(edUrl.Text)
4646
.Param('a', edA.Text)
47-
.Param('b', edB.Text));
48-
curl.SetRecvStream(stream, [csfAutoDestroy]);
49-
curl.Perform;
47+
.Param('b', edB.Text))
48+
.SetRecvStream(stream, [csfAutoDestroy])
49+
.Perform;
5050
memoResponse.Text := string(stream.Data)
5151
+ #13#10#13#10'URL: ' +
5252
string(curl.GetInfo(CURLINFO_EFFECTIVE_URL));

Examples/Easy_Http/AplusB_Post/f_Main.pas

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,29 @@ procedure TfmMain.btAddClick(Sender: TObject);
4040
form : ICurlForm;
4141
stream : TRawByteStream;
4242
begin
43-
curl := CurlGet;
43+
// Form
4444
form := CurlGetForm;
45-
stream := TRawByteStream.Create;
46-
47-
curl.SetUrl(edUrl.Text);
48-
curl.SetOpt(CURLOPT_POST, true);
49-
// I tested it on my free hosting — it has a bot protection.
50-
curl.SetUserAgent(FirefoxUserAgent);
51-
5245
// Complex version (requires additional headers)
5346
form.Add(CurlGetField
5447
.Name('a')
5548
.Content(edA.Text)
5649
.CustomHeaders(CurlGetSlist
5750
.AddRaw('Alpha: Bravo')
58-
.AddRaw('Charlie: Delta')));
51+
.AddRaw('Charlie: Delta')))
52+
// Simple version (just add a field)
53+
.Add('b', edB.Text);
5954

60-
// Simple version (just add a field)
61-
form.Add('b', edB.Text);
55+
// Stream
56+
stream := TRawByteStream.Create;
6257

63-
curl.Form := form;
64-
curl.SetRecvStream(stream, [csfAutoDestroy]);
65-
curl.Perform;
58+
curl := CurlGet;
59+
curl.SetUrl(edUrl.Text)
60+
.SetOpt(CURLOPT_POST, true)
61+
// I tested it on my free hosting — it has a bot protection.
62+
.SetUserAgent(FirefoxUserAgent)
63+
.SetForm(form)
64+
.SetRecvStream(stream, [csfAutoDestroy])
65+
.Perform;
6666
memoResponse.Text := string(stream.Data);
6767
end;
6868

Examples/Easy_Http/Https/Https.dpr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ var
1515
begin
1616
try
1717
curl := CurlGet;
18-
curl.SetUrl('https://ukr.net');
19-
curl.SetFollowLocation(true);
20-
curl.SetCaFile('cacert.pem');
21-
// Unicode is also supported!
22-
//curl.SetCaFile('α×β.pem');
23-
24-
// Perform the request, res will get the return code
25-
curl.Perform;
18+
curl.SetUrl('https://ukr.net')
19+
.SetFollowLocation(true)
20+
.SetCaFile('cacert.pem')
21+
// Unicode is also supported!
22+
//.SetCaFile('α×β.pem')
23+
// Perform the request, res will get the return code
24+
.Perform;
2625

2726
// Check for errors
27+
Writeln;
2828
Writeln(Format('HTTP response code: %d', [ curl.GetResponseCode ] ));
2929
except
3030
on e : Exception do

Examples/Easy_Http/PhotoInfo/f_Main.pas

Lines changed: 39 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,10 @@ procedure TfmMain.btCloneDemoClick(Sender: TObject);
102102
if not GetFile(fname, ftype) then Exit;
103103

104104
curl1 := CurlGet;
105-
curl1.SetRecvStream(stream, [csfAutoRewind]);
106-
curl1.SetUrl(edUrl.Text);
107-
curl1.SetOpt(CURLOPT_POST, true);
108-
109-
curl1.Form := CurlGetForm.AddFile('photo', fname, ftype);
105+
curl1.SetRecvStream(stream, [csfAutoRewind])
106+
.SetUrl(edUrl.Text)
107+
.SetOpt(CURLOPT_POST, true)
108+
.SetForm(CurlGetForm.AddFile('photo', fname, ftype));
110109

111110
curl2 := curl1.Clone;
112111
curl2.Perform;
@@ -123,13 +122,11 @@ procedure TfmMain.btEasyClick(Sender: TObject);
123122
if not GetFile(fname, ftype) then Exit;
124123

125124
curl := CurlGet;
126-
curl.SetRecvStream(stream, [csfAutoRewind]);
127-
curl.SetUrl(edUrl.Text);
128-
curl.SetOpt(CURLOPT_POST, true);
129-
130-
curl.Form := CurlGetForm.AddFile('photo', fname, ftype);
131-
132-
curl.Perform;
125+
curl.SetRecvStream(stream, [csfAutoRewind])
126+
.SetUrl(edUrl.Text)
127+
.SetOpt(CURLOPT_POST, true)
128+
.SetForm(CurlGetForm.AddFile('photo', fname, ftype))
129+
.Perform;
133130
memoResponse.Text := UTF8ToString(stream.Data);
134131
end;
135132

@@ -143,17 +140,16 @@ procedure TfmMain.btHardClick(Sender: TObject);
143140
if not GetFile(fname, ftype) then Exit;
144141

145142
curl := CurlGet;
146-
curl.SetRecvStream(stream, [csfAutoRewind]);
147-
curl.SetUrl(edUrl.Text);
148-
curl.SetOpt(CURLOPT_POST, true);
149-
150-
curl.Form := CurlGetForm.Add(
143+
curl.SetRecvStream(stream, [csfAutoRewind])
144+
.SetUrl(edUrl.Text)
145+
.SetOpt(CURLOPT_POST, true)
146+
.SetForm(CurlGetForm.Add(
151147
CurlGetField
152148
.Name('photo')
153149
.UploadFile(fname)
154-
.ContentType(ftype));
150+
.ContentType(ftype)))
151+
.Perform;
155152

156-
curl.Perform;
157153
memoResponse.Text := UTF8ToString(stream.Data);
158154
end;
159155

@@ -163,15 +159,13 @@ procedure TfmMain.btSynthMemory2Click(Sender: TObject);
163159
begin
164160
// cURL
165161
curl := CurlGet;
166-
curl.SetRecvStream(stream, [csfAutoRewind]);
167-
curl.SetUrl(edUrl.Text);
168-
curl.SetOpt(CURLOPT_POST, true);
169-
170-
curl.Form := CurlGetForm.AddFileBuffer(
162+
curl.SetRecvStream(stream, [csfAutoRewind])
163+
.SetUrl(edUrl.Text)
164+
.SetOpt(CURLOPT_POST, true)
165+
.SetForm(CurlGetForm.AddFileBuffer(
171166
'photo', 'synth_buffer2.png', 'image/png',
172-
pngStream.Size, pngStream.Memory^);
173-
174-
curl.Perform;
167+
pngStream.Size, pngStream.Memory^))
168+
.Perform;
175169
memoResponse.Text := UTF8ToString(stream.Data);
176170
end;
177171

@@ -184,14 +178,12 @@ procedure TfmMain.btSynthMemory3Click(Sender: TObject);
184178
Move(pngStream.Memory^, PAnsiChar(str)^, pngStream.Size);
185179
// cURL
186180
curl := CurlGet;
187-
curl.SetRecvStream(stream, [csfAutoRewind]);
188-
curl.SetUrl(edUrl.Text);
189-
curl.SetOpt(CURLOPT_POST, true);
190-
191-
curl.Form := CurlGetForm.AddFileBuffer(
192-
'photo', 'synth_buffer3.png', 'image/png', str);
193-
194-
curl.Perform;
181+
curl.SetRecvStream(stream, [csfAutoRewind])
182+
.SetUrl(edUrl.Text)
183+
.SetOpt(CURLOPT_POST, true)
184+
.SetForm(CurlGetForm.AddFileBuffer(
185+
'photo', 'synth_buffer3.png', 'image/png', str))
186+
.Perform;
195187
memoResponse.Text := UTF8ToString(stream.Data);
196188
end;
197189

@@ -201,18 +193,16 @@ procedure TfmMain.btSynthMemoryClick(Sender: TObject);
201193
begin
202194
// cURL
203195
curl := CurlGet;
204-
curl.SetRecvStream(stream, [csfAutoRewind]);
205-
curl.SetUrl(edUrl.Text);
206-
curl.SetOpt(CURLOPT_POST, true);
207-
208-
curl.Form := CurlGetForm.Add(
196+
curl.SetRecvStream(stream, [csfAutoRewind])
197+
.SetUrl(edUrl.Text)
198+
.SetOpt(CURLOPT_POST, true)
199+
.SetForm(CurlGetForm.Add(
209200
CurlGetField
210201
.Name('photo')
211202
.FileBuffer(
212203
'synth_buffer.png', pngStream.Size, pngStream.Memory^)
213-
.ContentType('image/png'));
214-
215-
curl.Perform;
204+
.ContentType('image/png')))
205+
.Perform;
216206
memoResponse.Text := UTF8ToString(stream.Data);
217207
end;
218208

@@ -225,18 +215,16 @@ procedure TfmMain.btSynthStreamClick(Sender: TObject);
225215

226216
// cURL
227217
curl := CurlGet;
228-
curl.SetRecvStream(stream, [csfAutoRewind]);
229-
curl.SetUrl(edUrl.Text);
230-
curl.SetOpt(CURLOPT_POST, true);
231-
232-
curl.Form := CurlGetForm.Add(
218+
curl.SetRecvStream(stream, [csfAutoRewind])
219+
.SetUrl(edUrl.Text)
220+
.SetOpt(CURLOPT_POST, true)
221+
.SetForm( CurlGetForm.Add(
233222
CurlGetField
234223
.Name('photo')
235224
.FileStream(pngStream, [csfAutoRewind])
236225
.ContentType('image/png')
237-
.FileName('synth_stream.png'));
238-
239-
curl.Perform;
226+
.FileName('synth_stream.png')))
227+
.Perform;
240228
memoResponse.Text := UTF8ToString(stream.Data);
241229
end;
242230

Examples/Easy_Http/StreamedDl/StreamedDl.dpr

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,20 @@ var
2323
rbs : TRawByteStream;
2424
begin
2525
try
26-
curl := CurlGet;
27-
curl.setUrl(Url);
28-
curl.SetFollowLocation(true);
29-
3026
fs := TFileStream.Create('index.html', fmCreate);
31-
curl.SetRecvStream(fs, [csfAutoDestroy]);
3227

33-
// Perform the request
34-
curl.Perform;
28+
curl := CurlGet;
29+
curl.setUrl(Url)
30+
.SetFollowLocation(true)
31+
.SetRecvStream(fs, [csfAutoDestroy])
32+
// Perform the request
33+
.Perform;
3534

3635
// Perform once again, to RawByteStream.
3736
// And write the first 1000
3837
rbs := TRawByteStream.Create;
39-
curl.SetRecvStream(rbs, [csfAutoDestroy]);
40-
curl.Perform;
38+
curl.SetRecvStream(rbs, [csfAutoDestroy])
39+
.Perform;
4140
Writeln(Copy(rbs.Data, 1, 1000));
4241

4342
// Check for some info

0 commit comments

Comments
 (0)