Recent

Poll

How should my program get the OpenSSL package

Program should download it to project directory every time it starts
0 (0%)
Program's installer/user should be the only thing to download/install OpenSSL
4 (100%)

Total Members Voted: 4

Author Topic: Can't use fphttpclient to GET HTML  (Read 1210 times)

anon101

  • New member
  • *
  • Posts: 12
Can't use fphttpclient to GET HTML
« on: November 23, 2018, 02:05:29 am »
Hey guys,
I'm trying to use Trello's API to get some stuff ('https://api.trello.com/1/members/me/boards?key={yourKey}&token={yourToken}'). However, I keep getting this error:
"Exception class 'EInOutError' with message:
Could not initialize OpenSSL library".

By the way, I'm trying to use this code (where URL is just a string):
Code: Pascal  [Select]
  1. Result := TFPCustomHTTPClient.SimpleGet(url);

I've googled this, but haven't found anything. It does work for getting, for example, a google page, however not for their API.

Thanks for any help/feedback from you guys!
« Last Edit: November 23, 2018, 02:10:14 am by anon101 »

Mocte

  • New member
  • *
  • Posts: 19
Re: Can't use fphttpclient to GET HTML
« Reply #1 on: November 23, 2018, 05:08:53 am »
Hi anon101

Seems like the openssl libraries are missing, see :

http://wiki.lazarus.freepascal.org/fphttpclient

anon101

  • New member
  • *
  • Posts: 12
Re: Can't use fphttpclient to GET HTML
« Reply #2 on: November 23, 2018, 05:43:26 am »
Aren't they built into Lazarus.
Because I want to be able to compile this afterwards and have it just work everywhere on every operating system. That's why I'm using Lazarus. It says there that it
Quote
will ship with version 2.8.0 and above

Thanks a load
« Last Edit: November 23, 2018, 05:45:11 am by anon101 »

CCRDude

  • Sr. Member
  • ****
  • Posts: 431
Re: Can't use fphttpclient to GET HTML
« Reply #3 on: November 23, 2018, 11:03:06 am »
Even if the external libraries are "shipped" (haven't verified that), that doesn't mean they're built into it. You still have to make them available on every computer the application runs. Like put them into the same folder as the executable. That makes sense anyway since OpenSSL libraries are updated often and you should use the newest (of the compatible branch).

rvk

  • Hero Member
  • *****
  • Posts: 3502
Re: Can't use fphttpclient to GET HTML
« Reply #4 on: November 23, 2018, 11:38:20 am »
I had a procedure to download openssl from http://indy.fulgan.com/SSL/ automatically when not available.
There was no need for https so you could download openssl with Lazarus itself (with TFPCustomHTTPClient.SimpleGet()).

To my horror I now see fulgan switched to a redirect to https. So downloading openssl isn't possible anymore without a third-party program  :'( :'( :'(

I guess that'll need to be changed by calling URLDownloadToFile() (on Windows) to download openssl from https.
« Last Edit: November 23, 2018, 11:50:37 am by rvk »

GetMem

  • Hero Member
  • *****
  • Posts: 3251
Re: Can't use fphttpclient to GET HTML
« Reply #5 on: November 23, 2018, 11:56:41 am »
@rvk
Quote
To my horror I now see fulgan switched to a redirect to https. So downloading openssl isn't possible anymore without a third-party program  :'( :'( :'(
AFAIK this still works:
Code: Pascal  [Select]
  1. uses fphttpclient, zipper;
  2.  
  3. function IsOpenSSLAvailable: Boolean;
  4. const
  5.   {$IFDEF WIN64}
  6.     cOpenSSLURL = 'http://packages.lazarus-ide.org/openssl-1.0.2j-x64_86-win64.zip';
  7.   {$ENDIF}
  8.   {$IFDEF WIN32}
  9.     cOpenSSLURL = 'http://packages.lazarus-ide.org/openssl-1.0.2j-i386-win32.zip';
  10.   {$ENDIF}
  11. var
  12.   {$IFDEF MSWINDOWS}
  13.   UnZipper: TUnZipper;
  14.   ParamPath, LibeayDLL, SsleayDLL, ZipFile: String;
  15.   HTTPClient: TFPHTTPClient;
  16.   {$EndIf}
  17. begin
  18.   {$IFDEF MSWINDOWS}
  19.   ParamPath := ExtractFilePath(ParamStr(0));
  20.   LibeayDLL := ParamPath + 'libeay32.dll';
  21.   SsleayDLL := ParamPath + 'ssleay32.dll';
  22.   Result := FileExists(Libeaydll) and FileExists(Ssleaydll);
  23.   if not Result then
  24.   begin
  25.     ZipFile := ParamPath + ExtractFileName(cOpenSSLURL);
  26.     HTTPClient := TFPHTTPClient.Create(nil);
  27.     try
  28.       try
  29.         HTTPClient.Get(cOpenSSLURL, ZipFile);
  30.        except
  31.        end;
  32.     finally
  33.       HTTPClient.Free;
  34.     end;
  35.     if FileExists(ZipFile) then
  36.     begin
  37.       UnZipper := TUnZipper.Create;
  38.       try
  39.         try
  40.           UnZipper.FileName := ZipFile;
  41.           UnZipper.Examine;
  42.           UnZipper.UnZipAllFiles;
  43.         except
  44.         end;
  45.       finally
  46.         UnZipper.Free;
  47.       end;
  48.       DeleteFile(ZipFile);
  49.       Result := FileExists(Libeaydll) and FileExists(Ssleaydll);
  50.     end;
  51.   end;
  52.   {$ELSE}
  53.   Result := True;
  54.   {$ENDIF}
  55. end;
  56.  
  57. procedure TForm1.Button1Click(Sender: TObject);
  58. begin
  59.   if IsOpenSSLAvailable then
  60.      //do something
  61. end;
  62.  
« Last Edit: November 23, 2018, 11:59:36 am by GetMem »

rvk

  • Hero Member
  • *****
  • Posts: 3502
Re: Can't use fphttpclient to GET HTML
« Reply #6 on: November 23, 2018, 12:01:52 pm »
@rvk
Quote
To my horror I now see fulgan switched to a redirect to https. So downloading openssl isn't possible anymore without a third-party program  :'( :'( :'(
AFAIK this still works, it will only download the dll's if not present in the current directory:
Ah, thanks. Didn't know http://packages.lazarus-ide.org also had them.

Luckily for my Delphi program I use my own cache. My program tries to download openssl32.zip or openssl64.zip. And on my server-side I redirect them to the latest OpenSSL version I have on that server. That way I can update them server-side without changing the program's at the client-side.

Thaddy

  • Hero Member
  • *****
  • Posts: 7178
Re: Can't use fphttpclient to GET HTML
« Reply #7 on: November 23, 2018, 12:03:01 pm »
I had a procedure to download openssl from http://indy.fulgan.com/SSL/ automatically when not available.
There was no need for https so you could download openssl with Lazarus itself (with TFPCustomHTTPClient.SimpleGet()).

To my horror I now see fulgan switched to a redirect to https. So downloading openssl isn't possible anymore without a third-party program  :'( :'( :'(

I guess that'll need to be changed by calling URLDownloadToFile() (on Windows) to download openssl from https.
Quite so. Curious about Rik's problem?
[edit] never mind posts crossed.
inline variables like in D10.3 are a bit like Brexit: if you are given the wrong information it sounds like a good idea. Every kid loves candy, but it makes you fat and your teeth will disappear.

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1013
Re: Can't use fphttpclient to GET HTML
« Reply #8 on: November 23, 2018, 12:45:01 pm »
On Windows, you can use this to download through https:

Code: Pascal  [Select]
  1. function DownloadByPowerShell(URL, TargetFile: string): boolean;
  2. var
  3.   Output:string;
  4. begin
  5.   result:=(ExecuteCommand('powershell -command "(new-object System.Net.WebClient).DownloadFile('''+URL+''','''+TargetFile+''')"', Output, False)=0);
  6. end;
  7.  

BeniBela

  • Hero Member
  • *****
  • Posts: 634
    • homepage
Re: Can't use fphttpclient to GET HTML
« Reply #9 on: November 23, 2018, 07:51:50 pm »
My Internet Tools do not need openssl for  HTTPS requests, because they use  the Windows Internet API for that

anon101

  • New member
  • *
  • Posts: 12
Re: Can't use fphttpclient to GET HTML
« Reply #10 on: November 23, 2018, 11:46:21 pm »
I had a procedure to download openssl from http://indy.fulgan.com/SSL/ automatically when not available.
There was no need for https so you could download openssl with Lazarus itself (with TFPCustomHTTPClient.SimpleGet()).

To my horror I now see fulgan switched to a redirect to https. So downloading openssl isn't possible anymore without a third-party program  :'( :'( :'(

I guess that'll need to be changed by calling URLDownloadToFile() (on Windows) to download openssl from https.
So you're saying I need to get my program itself to download and put OpenSSL into the project directory?
Would the program just download it to the folder its in, or how should I go about doing this in the best possible way?
Also, so I wouldn't need to restart the program after it downloaded OpenSSL?
And by the way, I want my program's code to run on windows, mac os x, linux and android (if possible, as this is the reason why I'm using Lazarus and learning Pascall).
Thanks,
Anon101
« Last Edit: November 23, 2018, 11:48:38 pm by anon101 »

rvk

  • Hero Member
  • *****
  • Posts: 3502
Re: Can't use fphttpclient to GET HTML
« Reply #11 on: November 23, 2018, 11:52:36 pm »
I had a procedure to download openssl from http://indy.fulgan.com/SSL/ automatically when not available.
There was no need for https so you could download openssl with Lazarus itself (with TFPCustomHTTPClient.SimpleGet()).
So you're saying I need to get my program itself to download and put OpenSSL into the project directory?
Would the program just download it to the folder its in, or how should I go about doing this in the best possible way?
Yes, exactly.

The code GetMem showed will do exactly that. You don't need to restart your program because the dlls are loaded when they are needed and if you call IsOpenSSLAvailable before that, all should be well.

lucamar

  • Sr. Member
  • ****
  • Posts: 463
Re: Can't use fphttpclient to GET HTML
« Reply #12 on: November 24, 2018, 12:30:06 am »
So you're saying I need to get my program itself to download and put OpenSSL into the project directory?
Would the program just download it to the folder its in, or how should I go about doing this in the best possible way?
Yes, exactly.

The code GetMem showed will do exactly that. You don't need to restart your program because the dlls are loaded when they are needed and if you call IsOpenSSLAvailable before that, all should be well.

Nevertheless, I think that installing any neeed DLLs is up to the install program, not something your program should do by itself if it's not happy :) Note also that your program may not have (most probably hasn't) write permission to its own folder, so that approach would either fail or make it install the DLLs in its config. directory, which is ... "not ideal".

ETA: Talking about deployment of the program, of course, not development.
« Last Edit: November 24, 2018, 01:20:22 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 1.8.4/FPC 3.0.4 on:
(K)Ubuntu 11..16, Windows XP SP3 (Home/Prof.) and various DOS incarnations.

anon101

  • New member
  • *
  • Posts: 12
Re: Can't use fphttpclient to GET HTML
« Reply #13 on: November 24, 2018, 10:06:15 am »
So you're saying I need to get my program itself to download and put OpenSSL into the project directory?
Would the program just download it to the folder its in, or how should I go about doing this in the best possible way?
Yes, exactly.

The code GetMem showed will do exactly that. You don't need to restart your program because the dlls are loaded when they are needed and if you call IsOpenSSLAvailable before that, all should be well.

Nevertheless, I think that installing any needed DLLs is up to the install program, not something your program should do by itself if it's not happy :) Note also that your program may not have (most probably hasn't) write permission to its own folder, so that approach would either fail or make it install the DLLs in its config. directory, which is ... "not ideal".

ETA: Talking about deployment of the program, of course, not development.
So, how exactly would I go about developing/deploying my application?
For now, should I just install it on my own machine? Would the software still be able to run in like a portable form?
My questions may seem a slight bit stupid, but to be honest, I've only ever really done development stuff, I've never really considered potential issues with the deployment
Any advice would be appreciated!
« Last Edit: November 24, 2018, 10:08:23 am by anon101 »

anon101

  • New member
  • *
  • Posts: 12
Re: Can't use fphttpclient to GET HTML
« Reply #14 on: November 26, 2018, 09:40:29 pm »
How exactly can I create an installer for the application in Pascall with Lazarus to automatically install OpenSSL? Do I just leave that till later and install it on my own computer now?