0

I can push an encrypted piece of humidity data up to my Ubidots cloud database by simply loading the following url in a web browser:

https://industrial.ubidots.com/api/v1.6/devices/MYDEVICENAME/?token=MYTOKENHERE&_method=post&humidity=15.9

When I do that, I get the success response in the browser window

{"humidity": [{"status_code": 201}]}

and the data shows up in my data table on Ubidots.

Now, I want to do this from an FMX app (C++ on Win32) without a visible browser, and I would like to check that I get the nice "201" response code. I looked at this link and cobbled up the following line of code:

Memo1->Text = IdHTTP1->Get("https://industrial.ubidots.com/api/v1.6/devices/MYDEVICENAME/?token=MYTOKENHERE&_method=post&humidity=6.9");

When I run it, I get a "Could not load SSL library" error message. How do I tell TIdHTTP to use SSL so it can handle the HTTPS? Is there a better, cleaner way to do this?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
relayman357
  • 793
  • 1
  • 6
  • 30

1 Answers1

1

I get a "Could not load SSL library" error message.

Indy uses OpenSSL by default. You can use Indy's WhichFailedToLoad() function in IdSSLOpenSSLHeaders.hpp to find out why it couldn't load the OpenSSL library.

How do I tell IdHTTP1 to use SSL

You already are, by virtue of requesting an HTTPS url. Indy is simply having trouble loading the SSL library, either because it can't find the library binaries, or you have the wrong versions of the binaries. You can get Indy compatible OpenSSL binaries from https://indy.fulgan.com/SSL/. Typically you should place them in the same folder as your app, but if you want to store them somewhere else then you need to call Indy's IdOpenSSLSetLibPath() function before invoking any SSL/TLS operations.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Remy, having trouble on iOS. I read [this link](http://docwiki.embarcadero.com/RADStudio/Rio/en/OpenSSL) and it said to get `libcrypto.a` and `libssl.a` SSL static library files from [this github](https://github.com/st3fan/ios-openssl) and copy them to proper folders under Embarcadero. Then [this link](http://docwiki.embarcadero.com/RADStudio/Rio/en/Creating_an_iOS_App#OpenSSL_Support) said to turn on "Link with SSL and Crypto" under Project->Options->C++ Linker. When i went to the github site to get the static files the guy has put up a big warning message to not use them. – relayman357 Apr 23 '19 at 02:09
  • @relayman357 Indy compatible OpenSSL libs for iOS are available on Indy's Fulgan mirror, https://indy.fulgan.com/SSL/OpenSSLStaticLibs.7z – Remy Lebeau Apr 23 '19 at 02:27
  • Remy, i copied `libcrypto.a` and `libssl.a` to the `...\Studio\19.0\lib\iosDevice64\debug` folder and `\release` folder, then i set the C++ linker option i refer to above. But when i run on my iPhone i'm getting access violation. – relayman357 Apr 23 '19 at 21:32
  • @relayman357 I can't answer that with such limited info. You are just going to have to debug your app for yourself to figure out where the AV is coming from. – Remy Lebeau Apr 23 '19 at 21:35
  • Remy, understand - was really just wondering if the steps i took to add SSL to my iOS project was correct. Thanks for your help as usual sir. – relayman357 Apr 23 '19 at 21:45
  • Remy, i found the missing piece! I needed to include `IdSSLOpenSSLHeaders_Static.hpp` as explained [on this post](https://forums.embarcadero.com/thread.jspa?messageID=869158). Your old answer there once again helped me. – relayman357 Apr 23 '19 at 22:01
  • 1
    @relayman357 also see [Using Open SSL in Delphi iOS](http://blog.marcocantu.com/blog/using_ssl_delphi_ios.html) on Marco Cantu's blog. – Remy Lebeau Apr 23 '19 at 22:07