Page 1 of 1

TScHTTPWebRequest can't download file on https

Posted: Sun 29 May 2022 00:56
by andydai
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.

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;

Re: TScHTTPWebRequest can't download file on https

Posted: Fri 03 Jun 2022 14:12
by MaximG
Thank you for the information. We will investigate the described issue and let you know the results shortly.

Re: TScHTTPWebRequest can't download file on https

Posted: Thu 16 Jun 2022 10:53
by MaximG
We checked the operation of our components and couldn't detect any problems. Please, let us know which version of SecureBridge you are using. Also, make sure the SSLOptions.Protocols of the ScHttpWebRequest component you are using is set to [spTls12, spTls13]