ScHttpWebRequest Example

Discussion of open issues, suggestions and bugs regarding network security and data protection solution - SecureBridge
Post Reply
multimesut
Posts: 18
Joined: Mon 28 Nov 2011 18:04
Location: Türkiye

ScHttpWebRequest Example

Post by multimesut » Mon 27 Nov 2017 15:05

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..

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: ScHttpWebRequest Example

Post by ViktorV » Tue 28 Nov 2017 15:30

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;

multimesut
Posts: 18
Joined: Mon 28 Nov 2011 18:04
Location: Türkiye

Re: ScHttpWebRequest Example

Post by multimesut » Fri 01 Dec 2017 12:41

Thank you for the answer. where is this "ScHttpWebRequest" used? can I POST a file to a webpage?

stlcours
Posts: 33
Joined: Wed 14 Sep 2011 20:22

Re: ScHttpWebRequest Example

Post by stlcours » Fri 01 Dec 2017 12:51

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!

multimesut
Posts: 18
Joined: Mon 28 Nov 2011 18:04
Location: Türkiye

Re: ScHttpWebRequest Example

Post by multimesut » Sat 02 Dec 2017 08:22

yes, #stlcours. I agree with you. Thanks!

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: ScHttpWebRequest Example

Post by ViktorV » Wed 06 Dec 2017 13:35

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;
Last edited by ViktorV on Fri 08 Dec 2017 10:55, edited 1 time in total.

multimesut
Posts: 18
Joined: Mon 28 Nov 2011 18:04
Location: Türkiye

Re: ScHttpWebRequest Example

Post by multimesut » Thu 07 Dec 2017 14:43

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');

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: ScHttpWebRequest Example

Post by ViktorV » Fri 08 Dec 2017 11:21

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.

bo.gardmark
Posts: 2
Joined: Mon 26 Nov 2018 14:57

Re: ScHttpWebRequest Example

Post by bo.gardmark » Mon 26 Nov 2018 16:45

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.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: ScHttpWebRequest Example

Post by ViktorV » Tue 27 Nov 2018 14:02

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.

bo.gardmark
Posts: 2
Joined: Mon 26 Nov 2018 14:57

Re: ScHttpWebRequest Example

Post by bo.gardmark » Tue 27 Nov 2018 17:27

Thanks VictorV. I have filed a support ticket on the issue...

/Bo

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: ScHttpWebRequest Example

Post by ViktorV » Fri 30 Nov 2018 09:21

Thank you for the information. We have reproduced the issue and it will be fixed in the next build.

Post Reply