#1 2024-06-26 18:03:02

Uefi
Member
Registered: 2024-02-14
Posts: 23

Is it possible to make https requests through mORMot ?

Hello, I don’t understand how to make https requests via mORMot to get the source code of the page, can you please tell me an example of the code and which library to include?

Offline

#2 2024-06-26 20:30:05

tbo
Member
Registered: 2015-04-20
Posts: 340

Re: Is it possible to make https requests through mORMot ?

uses
  mormot.core.base,
  mormot.core.data,
  mormot.core.os,
  mormot.net.client;

var
  content: RawByteString;
begin
  content := HttpGet('https://tile.openstreetmap.org/10/549/339.png');
  if content <> '' then
    FileFromString(content, ChangeFileExt(ExeVersion.ProgramFileName, '.png'));

With best regards
Thomas

Offline

#3 2024-06-26 21:41:25

Uefi
Member
Registered: 2024-02-14
Posts: 23

Re: Is it possible to make https requests through mORMot ?

Thanks a lot, but for example I need to use my own user agent and proxy ?

I figured it all out, but I didn’t understand one thing: does it automatically determine the type of proxy HTTP, SOCKS4, SOCKS5 ?

procedure TForm2.Button1Click(Sender: TObject);
var
H:TSimpleHttpClient;
begin
H:=TSimpleHttpClient.Create(False);
h.UserAgent:='.....................';
h.Proxy:=????;
h.Request('https://', 'GET');
Memo1.Lines.Add(h.Body);
h.Free;
end;

Last edited by Uefi (2024-06-26 22:20:56)

Offline

#4 2024-06-27 07:30:35

Mo0211
Member
Registered: 2018-12-30
Posts: 21

Re: Is it possible to make https requests through mORMot ?

i add another question here.
This is very easy to use and seems to be very smooth!

Is there a possibility to use a socks5 proxy or is only a http proxy possible?

Offline

#5 2024-06-27 07:39:18

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,371
Website

Re: Is it possible to make https requests through mORMot ?

Sadly, only HTTP (or HTTPS) proxies are supported yet.

Offline

#6 2024-06-27 16:39:35

Uefi
Member
Registered: 2024-02-14
Posts: 23

Re: Is it possible to make https requests through mORMot ?

ab wrote:

Sadly, only HTTP (or HTTPS) proxies are supported yet.

Hello, should you submit a proxy directly :

h.Proxy:='0.0.0.0:8080'; // ?

I would also put KeepAlive, Header, Data, DataMimeType into separate entries since this is more convenient than:
http.Request(URL, 'GET', '', '', '', 100);

And it would be:
http.KeepAlive:=100;
http.Header.Add('Content-Type: text/html; charset=utf-8'); // Better here TStringlist
http.Data:='';
http.DataMimeType:='application/json';

Please reconsider this as I have found that http requests in mORMot are fast, much faster than Synapse!

Last edited by Uefi (2024-06-27 16:43:02)

Offline

#7 2024-07-01 09:47:10

keinn
Member
Registered: 2014-10-20
Posts: 103

Re: Is it possible to make https requests through mORMot ?

TSimpleHttpClient is very easy to use then other solutions, and it is 10x times faster than delphi TNetHTTPClient,
but it missing compressions, need to add  RegisterCompress after fHttps := MainHttpClass.Create or fHttp := THttpClientSocket.Open.

another thing is, our mormot httpclient do NOT handle cookies set by server (response header Set-Cookie:), delphi TNetHTTPClient handle cookies automaticly, but it is too slow,

TWinHttp handle cookies , but it's buggy.
it will be nice if it has these features.

Last edited by keinn (2024-07-01 09:53:39)

Offline

#8 2024-07-01 10:09:36

keinn
Member
Registered: 2014-10-20
Posts: 103

Re: Is it possible to make https requests through mORMot ?

ab wrote:

Sadly, only HTTP (or HTTPS) proxies are supported yet.

go through many  docs, it is not easy to use Proxies features with our mORMot.

programer these days use delphi /pascal  , do not have much high quality components to use, it is sad.

mormot2 is definely top one framework in pascal/delphi field.

http/https/socks5 proxy is very usefull feature, we are so behind other languages.

python4delphi is away to make up for this regret.

as a framework , mORMot do everything from scratch, it is too much work.

maybe ,mORMot should just wrap up well-known, excellent, and widely accepted third-party components to catch up.

like curl wrap up, or some c++ interface wrap up,
like https://github.com/salvadordf/ocvWrapper46.git (wraps up openCV)
https://github.com/pyscripter/python4delphi.git (python)
https://github.com/salvadordf/WebView4Delphi.git (cef ,webview)

Offline

#9 2024-07-01 10:18:54

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,371
Website

Re: Is it possible to make https requests through mORMot ?

You can use libcurl with mORMot.

Offline

#10 2024-07-08 09:29:50

Mo0211
Member
Registered: 2018-12-30
Posts: 21

Re: Is it possible to make https requests through mORMot ?

Hey @Ab
is it possible to use a socks5 proxy with libcurl?
I read that HttpGet does not use compression per default.
What would you advice to use performance wise for downloading text from a website programmatically?
I googled quite some time to find an example how to use libcurl with a proxy - do you have a quick sample for me?

thanks!

Offline

#11 2024-07-08 11:22:04

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,564
Website

Re: Is it possible to make https requests through mORMot ?

The easy way  to use proxy with curl is to set the environment variables http_proxy and https_proxy

Offline

Board footer

Powered by FluxBB