Can't use fphttpclient to GET HTML
lazarus / 38-Networking and Web Programming
----------------------------------------------------------------------
anon101 · 2018-11-23 01:05
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][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i 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!
----------------------------------------------------------------------
Mocte · 2018-11-23 04:08
Hi anon101
Seems like the openssl libraries are missing, see :
http://wiki.lazarus.freepascal.org/fphttpclient
----------------------------------------------------------------------
anon101 · 2018-11-23 04:43
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 Quotewill ship with version 2.8.0 and
above
Thanks a load
----------------------------------------------------------------------
CCRDude · 2018-11-23 10:03
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 · 2018-11-23 10:38
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.
----------------------------------------------------------------------
balazsszekely · 2018-11-23 10:56
@rvk
QuoteTo 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][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i uses
fphttpclient, zipper; function IsOpenSSLAvailable: Boolean;const
{$IFDEF WIN64} cOpenSSLURL = 'http://packages.lazarus-
ide.org/openssl-1.0.2j-x64_86-win64.zip'; {$ENDIF} {$IFDEF WIN32}
cOpenSSLURL = 'http://packages.lazarus-
ide.org/openssl-1.0.2j-i386-win32.zip'; {$ENDIF}var {$IFDEF
MSWINDOWS} UnZipper: TUnZipper; ParamPath, LibeayDLL, SsleayDLL,
ZipFile: String; HTTPClient: TFPHTTPClient; {$EndIf}begin {$IFDEF
MSWINDOWS} ParamPath := ExtractFilePath(ParamStr(0)); LibeayDLL :=
ParamPath + 'libeay32.dll'; SsleayDLL := ParamPath + 'ssleay32.dll';
Result := FileExists(Libeaydll) and FileExists(Ssleaydll); if not
Result then begin ZipFile := ParamPath +
ExtractFileName(cOpenSSLURL); HTTPClient :=
TFPHTTPClient.Create(nil); try try
HTTPClient.Get(cOpenSSLURL, ZipFile); except end;
finally HTTPClient.Free; end; if FileExists(ZipFile) then
begin UnZipper := TUnZipper.Create; try try
UnZipper.FileName := ZipFile; UnZipper.Examine;
UnZipper.UnZipAllFiles; except end; finally
UnZipper.Free; end; DeleteFile(ZipFile); Result :=
FileExists(Libeaydll) and FileExists(Ssleaydll); end; end;
{$ELSE} Result := True; {$ENDIF}end; procedure
TForm1.Button1Click(Sender: TObject);begin if IsOpenSSLAvailable
then //do somethingend;
----------------------------------------------------------------------
rvk · 2018-11-23 11:01
Quote from: GetMem on November 23, 2018, 11:56:41 am@rvk
QuoteTo 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 · 2018-11-23 11:03
Quote from: rvk on November 23, 2018, 11:38:20 amI 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.
----------------------------------------------------------------------
DonAlfredo · 2018-11-23 11:45
On Windows, you can use this to download through https:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i function
DownloadByPowerShell(URL, TargetFile: string): boolean;var
Output:string;begin result:=(ExecuteCommand('powershell -command
"(new-object
System.Net.WebClient).DownloadFile('''+URL+''','''+TargetFile+''')"',
Output, False)=0);end;
----------------------------------------------------------------------
BeniBela · 2018-11-23 18:51
My Internet Tools do not need openssl for HTTPS requests, because
they use the Windows Internet API for that
----------------------------------------------------------------------
anon101 · 2018-11-23 22:46
Quote from: rvk on November 23, 2018, 11:38:20 amI 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
----------------------------------------------------------------------
rvk · 2018-11-23 22:52
Quote from: anon101 on November 23, 2018, 11:46:21 pmQuote from: rvk
on November 23, 2018, 11:38:20 amI 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 · 2018-11-23 23:30
Quote from: rvk on November 23, 2018, 11:52:36 pmQuote from: anon101
on November 23, 2018, 11:46:21 pmSo 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.
----------------------------------------------------------------------
anon101 · 2018-11-24 09:06
Quote from: lucamar on November 24, 2018, 12:30:06 amQuote from: rvk
on November 23, 2018, 11:52:36 pmQuote from: anon101 on November 23,
2018, 11:46:21 pmSo 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!
----------------------------------------------------------------------
anon101 · 2018-11-26 20:40
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?
----------------------------------------------------------------------
rvk · 2018-11-26 22:05
http://wiki.lazarus.freepascal.org/Deploying_Your_Application
http://wiki.lazarus.freepascal.org/Inno_Setup_Usage
The Lazarus Windows installer itself is also created with Inno Setup.
http://wiki.freepascal.org/Lazarus_Installer
But I wouldn't worry about distribution until your application is
actually ready to be deployed.
Edit: I see there is a poll now. But there are lots of other options
available. And it all depends on your application and your clients.
1) install openssl during installation to system directory.
2) install openssl during installation to exe directory.
3) download openssl when not available systemwide
4) download openssl when not available in exe directory
5) download openssl each time when started (don't do this)
I usually choose option 4. But if you're distributing to big companies
with security settings etc. option 1 or 2 might be advisable.
But if you have just one .exe with no other files, distributing just
that .exe and downloading openssl is easiest.
----------------------------------------------------------------------
lucamar · 2018-11-26 22:21
You have usually much more control on your development environment so
that's not really an issue: if you need them you can download external
DLLs and put them wherever appropiate.
On deployment, though, things are not so easy: unless you can control
the deployment environment (like p.e. in so called "portable"
installations) you must attend to possible installation problems. The
usual way to do that is to let others worry about it and use one of
the many install-builders out there: Inno Setup, NSIS, Microsoft's own
(which I never remember how it's called), etc. Once you start going
down that way it's almost always easier to let the installer deal with
your dependencies.
Look into any typical application (LibreOffice, Firefox, etc.) install
and see how many third-party libraries they contain. Heck, OpenOffice
used to install even a minimal Python environment!
----------------------------------------------------------------------
anon101 · 2018-12-05 01:39
Quote from: rvk on November 26, 2018, 11:05:46
pmhttp://wiki.lazarus.freepascal.org/Deploying_Your_Application
http://wiki.lazarus.freepascal.org/Inno_Setup_Usage
The Lazarus Windows installer itself is also created with Inno Setup.
http://wiki.freepascal.org/Lazarus_Installer
But I wouldn't worry about distribution until your application is
actually ready to be deployed.
Edit: I see there is a poll now. But there are lots of other options
available. And it all depends on your application and your clients.
1) install openssl during installation to system directory.
2) install openssl during installation to exe directory.
3) download openssl when not available systemwide
4) download openssl when not available in exe directory
5) download openssl each time when started (don't do this)
I usually choose option 4. But if you're distributing to big companies
with security settings etc. option 1 or 2 might be advisable.
But if you have just one .exe with no other files, distributing just
that .exe and downloading openssl is easiest.
Hey, thanks for the info and sorry for the delay. I've been very busy
lately.
I'll probably go with option 4 then with Inno setup wizard. It seems
the best for me. This would easily work on most OS's though right?
I just need Windows, Mac OS X, Linux and if possible Android as well.
Thanks for all your help!
----------------------------------------------------------------------
CCRDude · 2018-12-05 11:03
On Windows, InnoSetup along with option 2 - installing to program
folder - would in my opinion be the best solution. Especially with
different OpenSSL versions out there, using one from the system
directory might not be a good idea. And if your code is statically
dynamically linking OpenSSL, it won't run without them. Microsofts own
MSI is required if you want to distribute through the Microsoft Store.
On MacOS, you can create .pkg installers using XCodes productbuild
command line tool, and would place the libraries within the app
bundle. But I would prefer using NSURLDelegate there to be independent
of OpenSSL/LibreSSL versions of the OS.
On Linux, this depends a lot on your packaging. For .deb and .rpm, you
could specify dependencies. If you want to ship them, take a look at
AppImage.
Downloading libraries in my opinion has the advantage of staying up to
date, but the disadvantage of having to implement a lot of validity
checking, and having permissions to write to the app folder, which is
not very user friendly.
So, to sum it up - distribution is quite different on each platform.
----------------------------------------------------------------------
anon101 · 2018-12-08 10:24
So what about Android and maybe IOS?
Also, if I was to opt to let the user install it themselves, would
this reduce the difficulty of deploying for different platforms.
Since this is a small and simple utility project though, what should I
do, I just want to make sure that maybe when I get a new phone or a
friend on maybe OS X wants to use my program, I can pretty easily get
it working for them without too much problems.
What's the simplist thing I can do for max platforms? I mean hasn't an
SSL client or whatever been designed in pure Free Pascal so I don't
have to have this trouble? I only want something which can get and
post https requests. Nothing complex.
Again, thanks so much!!!
----------------------------------------------------------------------
lucamar · 2018-12-08 11:55
Quote from: anon101 on December 08, 2018, 11:24:05 amWhat's the
simplist thing I can do for max platforms? I mean hasn't an SSL client
or whatever been designed in pure Free Pascal so I don't have to have
this trouble? I only want something which can get and post https
requests. Nothing complex.
SSL/TLS is complex (each day more, it seems) and AFAIK there's no
pure-pascal "client". But take heart: most current platforms use
OpenSSL or a simil thereof (LibreSSL in MacOS/iOS) with the glaring
exception of Windows so your problem will most likely arise there (in
Windows) and the best solution, as indicated various times, is to let
the installer deal with OpenSSL along with your program.
----------------------------------------------------------------------
anon101 · 2018-12-18 03:08
I've installed OpenSSL using the link provided in the Lazarus
FPHTTPClient forum (the OpenSSL's recommended one for developers).
However I'm still getting the exact same error.
What do I do now?
By the way, sorry for writing this now, but I've only just gotten time
to start working on this again.
Thanks for everyone's advice!