Recent

Author Topic: Cannot connect to https://api.1nce.com using TFPHTTPClient  (Read 10324 times)

jeff

  • New Member
  • *
  • Posts: 18
Cannot connect to https://api.1nce.com using TFPHTTPClient
« on: June 26, 2020, 08:37:11 am »
Hi,
as the title says, the following code doesn't work, I get the error message 'Connect to api.1nce.com:443 failed'. The ssl libraries are installed, and I can connect to https websites except for this one. I tried debugging the fphttpclient unit, and the exception fires at line 624, which is FSocket.Connect; in TFPCustomHTTPClient.ConnectToServer procedure. I'm stuck here. Any suggestion how to fix this?

Code: Pascal  [Select][+][-]
  1. SMSGTW:=TFPHTTPClient.Create(nil);
  2. try
  3.    s:=SMSGTW.Get('https://api.1nce.com/management-api/swagger-ui.html');
  4.    Log.Append(s);
  5. except
  6.    on E: Exception do
  7.       ShowMessage(E.Message);
  8.    else raise;
  9. end;
  10.  

paweld

  • Hero Member
  • *****
  • Posts: 970
Re: Cannot connect to https://api.1nce.com using TFPHTTPClient
« Reply #1 on: June 26, 2020, 09:14:41 am »
Code: Pascal  [Select][+][-]
  1. uses
  2.   fphttpclient, opensslsockets;
  3.  
  4. procedure TForm1.Button1Click(Sender: TObject);
  5. var
  6.   SMSGTW: TFPHTTPClient;
  7.   s: String;
  8. begin
  9.   SMSGTW:=TFPHTTPClient.Create(nil);
  10.   try
  11.     s:=SMSGTW.Get('https://api.1nce.com/management-api/swagger-ui.html');
  12.     ShowMessage(s);
  13.   except
  14.     on E: Exception do
  15.     ShowMessage(E.Message);
  16.   end;
  17. end;
Best regards / Pozdrawiam
paweld

yus

  • Jr. Member
  • **
  • Posts: 57
Re: Cannot connect to https://api.1nce.com using TFPHTTPClient
« Reply #2 on: June 26, 2020, 09:33:18 am »
I had a problem with SSL in a multi-threaded application.
Try add
Code: Pascal  [Select][+][-]
  1. InitSSLInterface;

jeff

  • New Member
  • *
  • Posts: 18
Re: Cannot connect to https://api.1nce.com using TFPHTTPClient
« Reply #3 on: June 26, 2020, 10:34:09 am »
Thanks, but it didn't help.

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: Cannot connect to https://api.1nce.com using TFPHTTPClient
« Reply #4 on: June 26, 2020, 10:36:44 am »
Does that website require special handling e.g it needs API key (or something close to) to passed via cookies?

jeff

  • New Member
  • *
  • Posts: 18
Re: Cannot connect to https://api.1nce.com using TFPHTTPClient
« Reply #5 on: June 26, 2020, 11:08:28 am »
This website has an API that can be used with http calls. I have already implemented this in Java but I need it in freepascal too for a small utility. I didn't want to upload the whole project here, so the code above is only a stripped down example. The site 'https://api.1nce.com/management-api/swagger-ui.html' is a regular website (you can check it in a browser) but it demonstrates the problem as it cannot be connected to with fphttpclient. I don't know if this is due to a bug or I'm doing something wrong, to be honest I'm not really good at network related stuff.

yus

  • Jr. Member
  • **
  • Posts: 57
Re: Cannot connect to https://api.1nce.com using TFPHTTPClient
« Reply #6 on: June 26, 2020, 12:08:35 pm »
I tried your code, it works. I get the HTML page of the specified URL.

jeff

  • New Member
  • *
  • Posts: 18
Re: Cannot connect to https://api.1nce.com using TFPHTTPClient
« Reply #7 on: June 26, 2020, 12:30:54 pm »
I tried your code, it works. I get the HTML page of the specified URL.
What is your free pascal version?

jeff

  • New Member
  • *
  • Posts: 18
Re: Cannot connect to https://api.1nce.com using TFPHTTPClient
« Reply #8 on: June 26, 2020, 12:57:51 pm »
I did a clean lazarus install, and now it is working. Thanks for your help.

wittbo

  • Full Member
  • ***
  • Posts: 150
Re: Cannot connect to https://api.1nce.com using TFPHTTPClient
« Reply #9 on: July 16, 2020, 06:12:41 pm »
I have just the same problem with this URL:  https://www.ariva.de.
Created a little testprogram like your example and could reproduce the error with the URL of jeff.

I believe this has something to do with the OpenSSLSockets unit, since this problem occurs when using Lazarus 2.0.10. In all previous versions of Lazarus, there was no problem loading the webpage and the sslsocket support was automatically compiled into the program.
-wittbo-
MBAir with MacOS 10.14.6 / Lazarus 2.2.4
MacStudio with MacOS 13.0.1 / Lazarus 2.2.4

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Cannot connect to https://api.1nce.com using TFPHTTPClient
« Reply #10 on: July 16, 2020, 06:32:43 pm »
I had similar or maybe the same issue when using Lazarus 2.0.8. The problem has been solved after I use Lazarus 2.0.10. The problem only happened when connecting to secure protocol (https) not http.

I heard there were some improvements (that can solve the SSL issue) in FPC 3.2.0. Lazarus 2.0.10 is using FPC 3.2.0. Maybe you can try to upgrade your Lazarus or FPC.

To make it works, Now in Lazarus 2.0.10 I have to put opensslsockets in the uses clause and no need to call InitSSLInterface.
« Last Edit: July 16, 2020, 06:37:44 pm by Handoko »

wittbo

  • Full Member
  • ***
  • Posts: 150
Re: Cannot connect to https://api.1nce.com using TFPHTTPClient
« Reply #11 on: July 18, 2020, 05:30:29 am »
In my case this is problem, which occurs with 2.0.10 only.
Deinstalled 2.0.10; reinstalled 2.0.8; compile, run:    no problem
Deinstalled 2.0.8; reinstalled 2.0.10; compile, run:   problem 'Connect to www.ariva.de:443 failed'
-wittbo-
MBAir with MacOS 10.14.6 / Lazarus 2.2.4
MacStudio with MacOS 13.0.1 / Lazarus 2.2.4

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Cannot connect to https://api.1nce.com using TFPHTTPClient
« Reply #12 on: July 18, 2020, 06:25:37 am »
I am writing a simple web page loader program. I tried to connect arriva front page. I managed to download the html correctly. I'm using Lazarus 2.0.10.

The problem happen only when calling:
IpHtmlPanel1.SetHtml(HTML);

It seems it failed to render the page that contain iframe, see the image below.

Previously, when using Lazarus 2.0.8 it always failed to connect any https sites. Lazarus 2.0.10 fixes the https issue.

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Cannot connect to https://api.1nce.com using TFPHTTPClient
« Reply #13 on: July 18, 2020, 06:32:26 am »
Wittbo, from your sig, you are using Mac ? and you have not mentioned the FPC version you are using.

On Linux, with FPC3.0.4 there were several ssl problems, one involved FPC looking for a particular name for the ssl libraries that was not normally there.  If you can run strace on the Mac, you might be able to see which ssl libraries your app is trying to use.

One rather silly solution to that problem on Linux was to install the dev library, it made a symlink that did have the name that FPC was looking for.  But this problem went away with FPC320.

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

wittbo

  • Full Member
  • ***
  • Posts: 150
Re: Cannot connect to https://api.1nce.com using TFPHTTPClient
« Reply #14 on: July 18, 2020, 07:13:49 am »
Sorry, my platform is MacBook Air with macOS 10.14.6.
And, as I mentioned, the errors only occurs with Lazarus 2.0.10 (which includes fpc 3.2.0). With all previous Lazarus versions (which include fpc 3.0.4), there is no problem.
-wittbo-
MBAir with MacOS 10.14.6 / Lazarus 2.2.4
MacStudio with MacOS 13.0.1 / Lazarus 2.2.4

 

TinyPortal © 2005-2018