#1 2023-07-10 13:23:21

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Tcurlhttp provides error in debug when running from Ubuntu

I am using thttprequest from mormot2 inside a service to get response from an external API and I am using Tcurlhttp to do the connection (plus the  USELIBCURL directive in the project's optionst)
The same code is compiled with delphi (windows) and FPC(Linux Ubuntu).
In windows it works OK with libcurl.dll v8.1.2.0 but in ubuntu linux (v7.81.0) I am getting the following error:

libcurl error 56 (Failure when receiving data from the peer)

I do not believe it is the difference between the curl version, because running the request from command line in linux, it works and it does not provide any error
The problem has probably to do with the input headers I add, as removing a header gives responce back.
I am adding the following way the headers:

headers:='Authorization: Basic '+BinToBase64(uname+':'+passw)+#10+'api-key: '+applkey+#10;
for n:=0 to high(headername) do
    headers:=headers+headername[n]+': '+headervalue[n]+#10;

I noticed that leaving Authorization only, or api-key only, I get no curl error, but the usual response page from the rest server requesting both. The rest server I am contacting is not mormot.
it seems not be an FPC problem, compiled in windows 64bit with FPC it works OK.

Does anyone can imagine a reason for this behavior of curl in linux when used through mormot?

@ab is mormot2 using its own code-library for curl, and not ubuntu's curl?
Thank you in advance

Offline

#2 2023-07-10 13:51:53

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

Re: Tcurlhttp provides error in debug when running from Ubuntu

dcoun wrote:

Does anyone can imagine a reason for this behavior of curl in linux when used through mormot?

Have you tried making the request pure with curl in mORMot? I have posted examples for different scenarios in this thread and some others.

With best regards
Thomas

Offline

#3 2023-07-10 13:53:39

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: Tcurlhttp provides error in debug when running from Ubuntu

No and thats a good idea. I will test it. Thank you

Offline

#4 2023-07-10 14:04:13

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

Re: Tcurlhttp provides error in debug when running from Ubuntu

For adding headers you can find an example here. Unfortunately, I have not created a list where I have written everywhere something on the topics. Must always search myself.

With best regards
Thomas

Offline

#5 2023-07-10 21:53:25

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

Re: Tcurlhttp provides error in debug when running from Ubuntu

Headers delimirer is CRLF (#13#10), not LF(#10) as in your example.

Offline

#6 2023-07-11 06:23:18

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

Re: Tcurlhttp provides error in debug when running from Ubuntu

Note that I would rather not use libcurl but the native mORMot 2 socket-based client.

Offline

#7 2023-07-11 11:52:02

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: Tcurlhttp provides error in debug when running from Ubuntu

Thank you very much for your answers
The following code works OK in Ubuntu when running from an interface in mormot:
https://gist.github.com/dkounal/b8ab592 … 7536a31623

I tried the +#13+#10, error still exists.
Do you recommend something else?

I will try now the THttpClientSocket. Or should I use the TSimpleHttpClient?
Is it possible to use compression with THttpClientSocket?

Last edited by dcoun (2023-07-11 11:56:05)

Offline

#8 2023-07-14 09:43:00

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: Tcurlhttp provides error in debug when running from Ubuntu

To finish with this thread,
using thttprequest and curl does not works from linux compiled with FPC returning error 56.
Same code compiled with FPC for win64 works OK in windows.
Using the above gist code from inside  mormot works ok for linux with linux
Headers were tested for both #13#10 and #10
I will try to check it again in the weekend.

Thank you all for the help. At least with curl it works now.

Last edited by dcoun (2023-07-14 09:43:32)

Offline

#9 2023-07-14 12:49:47

ttomas
Member
Registered: 2013-03-08
Posts: 135

Re: Tcurlhttp provides error in debug when running from Ubuntu

Try to remove last #13#10 in headers variable.

Offline

#10 2023-07-14 14:15:45

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: Tcurlhttp provides error in debug when running from Ubuntu

ttomas wrote:

Try to remove last #13#10 in headers variable.

I returned back my code to check and I found that now it is not needed even that.
The same code from repository that did not work yesterday morning, it works today for linux.
The only change, is that I upgraded last night fpcupdeluxe and I did also an update to the same fixes version of FPC+Lazarus.

To be honest I am a bit afraid to use fpc....

PS I always do clean, delete and compile. Debugger does not work without that.
Thank you all again

Last edited by dcoun (2023-07-14 14:17:30)

Offline

Board footer

Powered by FluxBB