TScHTTPWebRequest can't download file on https
Posted: Sun 29 May 2022 00:56
2 URLs
URL1 is https://hrs.hrservice.tw/_Update/DashboardSetup.exe
URL2 is https://download.iai.services/HRS/DashboardSetup.exe
Can download by browser.
In Delphi
URL1 download by TScHttpWebRequest is working. (Button1)
URL2 download by TScHttpWebRequest get Error "The other side has sent a failure alert :[70]" . (Button2)
and i try to use HttpException , but not wotrking.
How can the download URL2 be performed correctly?
Thanks.
URL1 is https://hrs.hrservice.tw/_Update/DashboardSetup.exe
URL2 is https://download.iai.services/HRS/DashboardSetup.exe
Can download by browser.
In Delphi
URL1 download by TScHttpWebRequest is working. (Button1)
URL2 download by TScHttpWebRequest get Error "The other side has sent a failure alert :[70]" . (Button2)
and i try to use HttpException , but not wotrking.
How can the download URL2 be performed correctly?
Thanks.
Code: Select all
procedure TForm1.DoOnProgress(Sender: TObject; Total, Current: Int64;
var Cancel: boolean);
begin
ProgressBar1.Position := Current;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
dfile:TFileStream;
HttpWebResponse: TScHttpWebResponse;
begin
dfile:=TFileStream.Create('.\DashboardSetup.exe',fmCreate);
try
try
ScHttpWebRequest.SSLOptions.TrustServerCertificate:=True;
ScHttpWebRequest.RequestUri := 'https://hrs.hrservice.tw/_Update/DashboardSetup.exe';
ScHttpWebRequest.Method := rmGET;
HttpWebResponse := ScHttpWebRequest.GetResponse;
HttpWebResponse.OnProgress := DoOnProgress;
HttpWebResponse.ReadToStream(dfile);
except
on E:Exception do begin
Button1.Caption:='Error';
//ShowMessage(E.ClassName+' : '+E.Message);
Label1.Caption:=E.ClassName+' : '+E.Message;
Exit;
end;
end;
finally
ScHttpWebRequest.Disconnect;
FreeAndNil(dfile);
end;
if FileExists('.\DashboardSetup.exe') and DeleteFile('.\DashboardSetup.exe') then begin
Button1.Caption:='Complete';
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
dfile:TFileStream;
HttpWebResponse: TScHttpWebResponse;
begin
dfile:=TFileStream.Create('.\DashboardSetup.exe',fmCreate);
try
try
ScHttpWebRequest.SSLOptions.TrustServerCertificate:=True;
ScHttpWebRequest.RequestUri := 'https://download.iai.services/HRS/DashboardSetup.exe';
ScHttpWebRequest.Method := rmGET;
HttpWebResponse := ScHttpWebRequest.GetResponse;
HttpWebResponse.OnProgress := DoOnProgress;
HttpWebResponse.ReadToStream(dfile);
{
except
on E:HttpException do begin // not working
Button2.Caption:='Error';
//ShowMessage(E.Code.ToString+' : '+E.ServerMessage);
Label2.Caption:=E.Code.ToString+' : '+E.ServerMessage;
Exit;
end;
}
except
on E:Exception do begin
Button2.Caption:='Error';
//ShowMessage(E.ClassName+' : '+E.Message);
Label2.Caption:=E.ClassName+' : '+E.Message;
Exit;
end;
end;
finally
ScHttpWebRequest.Disconnect;
FreeAndNil(dfile);
end;
if FileExists('.\DashboardSetup.exe') and DeleteFile('.\DashboardSetup.exe') then begin
Button2.Caption:='Complete';
end;
end;