Search code examples
firemonkeyc++builderindyidhttp

IdHTTP to ensure push data to Ubidots (FMX, WIN32)


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?


Solution

  • 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.