How to speed up HTTP thread using TTask in Delphi 10

  

i need a way to speed up this thread, i am using iTask threads in Delphi 10, i don’t know how to use multi Http threads so lHTPP.GetandlHTTP.Post becomes faster

more information: First login and getting access token and userid using lHTTPGet,then getting the unique end_cursor string from the first HTTP Post to use it in the For loop Post, each Reply from Post request has a end_cursor string that used in the next Post request and so on..now how can i write multiple post request at the same time?
my code :

procedure TForm1.Button9Click(Sender: TObject);
var
lHTTP: TIdHTTP;
IdSSL: TIdSSLIOHandlerSocketOpenSSL;
Params,Followers,Followers1 : TStrings;
Reply, Token, X: string;
Cookie: TIdCookie;
userid: string;
end_cursor : String;
begin
Params := TStringList.Create;
Params.Add(‘username=’ + Edit7.Text);
Params.Add(‘password=’ + Edit8.Text);
TTask.Create(
procedure
var
P : integer;
begin
//////////////////// LOGIN ///////////////////////////////////////////////////////
lHTTP := TIdHTTP.Create(nil);
try

lHTTP.HandleRedirects := True;
lHTTP.Request.UserAgent := ‘Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.76 Mobile Safari/537.36’;
lHTTP.Get(‘https://www.website.com’, TStream(nil));
try

Reply := lHTTP.Post(‘https://www.website.com, Params);
TThread.Synchronize(nil,
procedure
begin
Memo1.Lines.Add(Reply);
end
);
finally
end;
///////////////////////////////// LOGIN /////////////////////////////////////////////////////

lHTTP.Request.UserAgent := ‘Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.76 Mobile Safari/537.36’;
lHTTP.Request.Connection := ‘keep-alive’;
lHTTP.Get(‘https://www.website.com/’+Edit4.Text+’/’, TStream(nil));

cookie := lHTTP.CookieManager.CookieCollection.Cookie[‘id’, ‘www.website.com’];
if cookie <> nil then
token := cookie.Value
else
token := ”;

cookie := lHTTP.CookieManager.CookieCollection.Cookie[‘user_id’, ‘www.website.com’];
if cookie <> nil then
userid := cookie.Value; // <– add this
Params.Add(Edit3.Text)

lHTTP.Request.CustomHeaders.Values[‘X-id’] := token;
lHTTP.Request.CustomHeaders.Values[‘X-website-AJAX’] := ‘1’;
lHTTP.Request.CustomHeaders.Values[‘X-Requested-With’] := ‘XMLHttpRequest’;
lHTTP.Request.Referer := ‘https://www.website.com/’+Edit4.Text+’/’;
lHTTP.Request.ContentType := ‘application/x-www-form-urlencoded’;
lHTTP.Request.UserAgent := ‘Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.76 Mobile Safari/537.36’;
Reply := lHTTP.Post(‘https://www.website.com/query/’, Params);

TThread.Synchronize(nil,
procedure
begin
Memo3.Lines.Add(Reply);

end
);
Memo3.Lines.SaveToFile(‘C:1.txt’);
TThread.Synchronize(nil,
procedure
begin
end
);
Params.Clear;
TThread.Synchronize(nil,
procedure
begin
Button10Click(Self);
end
);
for P := 0 to 1000 do
begin
Params.Add(Edit3.Text);
try

lHTTP.Request.CustomHeaders.Values[‘X-id’] := token;
lHTTP.Request.CustomHeaders.Values[‘X-website-AJAX’] := ‘1’;
lHTTP.Request.CustomHeaders.Values[‘X-Requested-With’] := ‘XMLHttpRequest’;
lHTTP.Request.Referer := ‘https://www.website.com/’+Edit4.Text+’/’;
lHTTP.Request.ContentType := ‘application/x-www-form-urlencoded’;
lHTTP.Request.UserAgent := ‘Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.76 Mobile Safari/537.36’;
Reply := lHTTP.Post(‘https://www.website.com/query/’, Params);

TThread.Synchronize(nil,
procedure
begin
Memo4.Lines.Add(Reply)

end
);

if StrToInt(Label6.Text) > StrToInt(Label5.Text) then Break;

Finally
end;
end;
Finally
end;

end).Start;

end;

Comments are closed.