How to get TscHttpWebRequest progress?

Discussion of open issues, suggestions and bugs regarding network security and data protection solution - SecureBridge
Post Reply
andydai
Posts: 2
Joined: Tue 07 Sep 2021 04:58

How to get TscHttpWebRequest progress?

Post by andydai » Tue 07 Sep 2021 05:41

download file by URL by TscHttpWebRequest , how to get progress ??

Thanks

YanishevskiyVI
Devart Team
Posts: 70
Joined: Wed 02 Jun 2021 09:30

Re: How to get TscHttpWebRequest progress?

Post by YanishevskiyVI » Tue 07 Sep 2021 12:18

Hi Andy!

Thanks for your question!

To display the progress of download, you need to process TScHttpWebResponse.OnProgress event as follow:

Code: Select all

var 
  ScHttpWebResponse: TScHttpWebResponse;
... 
  ScHttpWebResponse := ScHttpWebRequest.GetResponse(); 
  ScHttpWebResponse.OnProgress := DoOnProgress; 
  //perform reading of response content 
... 
procedure TForm1.DoOnProgress(Sender: TObject; Total, Current: Int64; var Cancel: boolean); 
begin 
//here you can display a progress 
//assign Cancel := True; to stop downloading; 
end; 
Should you have any other questions, feel free to ask!

Regards,
Vitaliy

TB0815
Posts: 2
Joined: Sun 10 Oct 2021 10:35

Re: How to get TscHttpWebRequest progress?

Post by TB0815 » Sun 10 Oct 2021 10:39

Hello,

I tried this but got the following error messages:

Code: Select all

uutilshttp.pas(70,30) Error: Wrong number of parameters specified for call to "DoOnProgress"
uutilshttp.pas(32,15) Error: Found declaration: DoOnProgress(TObject;Int64;Int64;var Boolean);
Here is a code snippet:

Code: Select all

function TUtilsHTTP.GetHTTPResponse(URL: string; out HTTPResponse: string): boolean;
var
  Request: TScHttpWebRequest;
  Response: TScHttpWebResponse; 
begin
...
      Response := Request.GetResponse;
      Response.OnProgress := DoOnProgress;   
...
end;

procedure TUtilsHTTP.DoOnProgress(Sender: TObject; Total, Current: int64;
  var Cancel: boolean);
begin
  // Stop Download, wenn notwendig
  Cancel := FCancelDownload;  
end;
I am using Lazarus 2.0.12 with FPC 3.2.2. What are the correct parameters?

Can you please update your documentation? There are many missing parts!

TB0815
Posts: 2
Joined: Sun 10 Oct 2021 10:35

Re: How to get TscHttpWebRequest progress?

Post by TB0815 » Sun 10 Oct 2021 11:01

I got it...

Code: Select all

Response.OnProgress := @DoOnProgress;  
is the solution for Lazarus. Sry my fault.

But there are still a lot of missing parts in the documentation...

YanishevskiyVI
Devart Team
Posts: 70
Joined: Wed 02 Jun 2021 09:30

Re: How to get TscHttpWebRequest progress?

Post by YanishevskiyVI » Wed 13 Oct 2021 12:34

Hi there!

Thanks for the info provided!
Could you please inform us about the issues you have experienced, so that we could be able to improve our documentation?

Looking forward to your reply!

Post Reply