Page 1 of 1

ScHttpWebRequest Example

Posted: Mon 27 Nov 2017 15:05
by multimesut
hi, I could not find the example on the internet. how can i use it? is there a sample that makes an xml post on a host? thank you..

Re: ScHttpWebRequest Example

Posted: Tue 28 Nov 2017 15:30
by ViktorV
To solve the task, you can use the following code:

Code: Select all

var
  Request: TScHttpWebRequest;
  Response: TScHttpWebResponse;
  ResponseStr: string;
...
  Request := TScHttpWebRequest.Create('http://services.odata.org/Northwind/Northwind.svc/Orders()');
  try
    Response := Request.GetResponse;
    try
      ResponseStr := Response.ReadAsString;
      Memo.Lines.Text := ResponseStr;
    finally
      Response.Free;
    end;
  finally
    Request.Free;
  end;

Re: ScHttpWebRequest Example

Posted: Fri 01 Dec 2017 12:41
by multimesut
Thank you for the answer. where is this "ScHttpWebRequest" used? can I POST a file to a webpage?

Re: ScHttpWebRequest Example

Posted: Fri 01 Dec 2017 12:51
by stlcours
Yes,could we send the files by https using SB ? I hope you can add this features in the future!!
Or you can add a new example of https with SB and Indy/RTC/kbmmw, etc. Thanks!

Re: ScHttpWebRequest Example

Posted: Sat 02 Dec 2017 08:22
by multimesut
yes, #stlcours. I agree with you. Thanks!

Re: ScHttpWebRequest Example

Posted: Wed 06 Dec 2017 13:35
by ViktorV
The HTTP protocol is not directly designed for transferring files. TScHttpWebRequest allows you to transfer data using the POST query method.
To solve the task, you can use the following code:

Code: Select all

var
  Request: TScHttpWebRequest;
  Response: TScHttpWebResponse;
  ResponseStr: string;
  Buf: TBytes;
begin
  Request := TScHttpWebRequest.Create(URL);
  try
    Request.Method := rmPost;
    Buf := TEncoding.UTF8.GetBytes('This is a test that posts this string to a Web server.');

    Request.ContentType := 'application/x-www-form-urlencoded';
    Request.ContentLength := Length(Buf);
    Request.WriteBuffer(Buf);
    Response := Request.GetResponse;
    Response.Free;
  finally
    Request.Free;
  end;
end;

Re: ScHttpWebRequest Example

Posted: Thu 07 Dec 2017 14:43
by multimesut
Thank you for the answer. I will reach the solution. Can it be done at Basic Authorization? the following did not work.

Request := TScHttpWebRequest.Create('https://user:[email protected]/xml');

Re: ScHttpWebRequest Example

Posted: Fri 08 Dec 2017 11:21
by ViktorV
Yes, SecureBridge allows executing the specified query. Please make sure that you are using the correct URL query and inform whether this query is executed if you input it in the browser address line.

Re: ScHttpWebRequest Example

Posted: Mon 26 Nov 2018 16:45
by bo.gardmark
I’m testing the Devart “SecureBridge” to be able to snoop and extract web content via https. My intention is to login to a site, click on a report button and download the excel csv file that I will get in return to my local computer. As far as I understand this will be possible to do with the “SecureBridge” components.
As a first step I did the example given by ViktorV » Tue 28 Nov 2017 16:30 in the thread as shown below. However I get this error: “Invalid class typecast” at the line: “Response := Request.GetResponse;”. Why is that? Can anyone give me an advice…
Regards
Bo

Code: Select all

unit CsvMain;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, ScHttp, ScSSHClient, Vcl.StdCtrls, Vcl.Buttons;

type
  TForm2 = class(TForm)
    BbtnTest: TBitBtn;
    Memo1: TMemo;
    procedure BbtnTestClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;
  Request: TScHttpWebRequest;
  Response: TScHttpWebResponse;
  ResponseStr: string;

implementation

{$R *.dfm}

procedure TForm2.BbtnTestClick(Sender: TObject);
begin
  Request := TScHttpWebRequest.Create('https://esta.cbp.dhs.gov/esta/');
  try
    Response := Request.GetResponse;
    try
      ResponseStr := Response.ReadAsString;
      Memo1.Lines.Text := ResponseStr;
    finally
      Response.Free;
    end;
  finally
    Request.Free;
  end;
end;

end.

Re: ScHttpWebRequest Example

Posted: Tue 27 Nov 2018 14:02
by ViktorV
Unfortunately, we can't reproduce the issue on the last SecureBridge 8.2.4 version. When executing the specified code, we do not get an error.
Please check whether the issue is reproduced on the latest version of SecureBridge 8.2.4 If it is, please compose a full sample demonstrating the described behavior and send it to us via form e-support: https://www.devart.com/company/contactform.html, including the scripts for creating and filling database objects. Also, please specify the IDE version you are using.

Re: ScHttpWebRequest Example

Posted: Tue 27 Nov 2018 17:27
by bo.gardmark
Thanks VictorV. I have filed a support ticket on the issue...

/Bo

Re: ScHttpWebRequest Example

Posted: Fri 30 Nov 2018 09:21
by ViktorV
Thank you for the information. We have reproduced the issue and it will be fixed in the next build.