Jump to content
mdsantos

Using TLS 1.2 on XE4 to call webservice

Recommended Posts

Hi,

 

I have some legacy application written in C++ Builder XE4. Our client asked us to change some Webservices call to https TLS 1.2. And then problems started. We tried to use Indy HTTP to do this, but only TLS 1.0. was available, after a lot of digging and try outs, we were able to update Indy Components in XE4 (using the documentation available at https://github.com/IndySockets/Indy/wiki/Updating-Indy) and now we are able to do the call using TLS 1.2 

 

The problem now it's that the idHTTP post request is very slow to receive an response (it takes about a minute or more), using Postman it's less than a 1 sec.

 

Here is the code snippet:

 

    TIdSSLIOHandlerSocketOpenSSL *SSLHandler = new TIdSSLIOHandlerSocketOpenSSL(NULL);


    TIdHTTP *IdHTTP1 = new TIdHTTP(NULL);

    SSLHandler->SSLOptions->Method = sslvTLSv1_2;      //(we add to force this, otherwise we got the "Error connecting with SSL. error 1409442E:SSL routine:ssl3_read_bytes:tlsv1 alert protocol version")

    IdHTTP1->IOHandler = SSLHandler;

    IdHTTP1->Request->CustomHeaders->AddValue("X_API_KEY", "somevalue");
    IdHTTP1->Request->ContentType = "application/json";

    //IdHTTP1->Request->ContentType = tipo->Text;
    UnicodeString json = "[JSON DATA]"; // Replace with your JSON data
    TStringStream *ss = new TStringStream(json);
    UnicodeString response = IdHTTP1->Post("https://TheServiceURL", ss);   // ---> THIS TAKES ABOUT 1 MINUTE TO EXECUTE
    ShowMessage("Response Rest: " + response);  

 

 

Some help would be appreciated. Thank you.

 

 

 

Share this post


Link to post
2 hours ago, mdsantos said:

The problem now it's that the idHTTP post request is very slow to receive an response (it takes about a minute or more), using Postman it's less than a 1 sec.

Unless you are sending a massively large JSON, or receiving a massively large JSON, then it should not be taking anywhere near that long to encode/decode the data.  So I have to assume that either 1) you are on a very slow network, or 2) the response from the server is really taking that long to transmit.  Use a packet sniffer to check that, as well as to compare the Postman traffic to the TIdHTTP traffic any differences.

Share this post


Link to post

It's not the case. The json is small, just 237 chars.

 

Also tested with postman in the same machine, it took 1 sec to reply. Restarted the machine, and... the problem was gone, strange.

 

Even so the Indy upgrade was not a smooth ride. We follow the documentation, step by step:

 

- Automated Uninstall script for XE4 Clean_X4.cmd

- removing the packages from the IDE

- Build the indy project (C++ Builder) with the Fullc_XE4.bat

image.thumb.png.d0413cb9f39a7787db8046090cfa5d51.png

- Setting the lib paths Lib\core, lib\system, lib\protocolos

image.thumb.png.704a2059dc4b1c7be92da590bf633e99.png

image.thumb.png.b49f2db7a299f6f4d9da364f51851d81.png

 

but I got error installing the new packages. "Impossible to locate the specific module".

 

image.thumb.png.f50f8d163a4be52670a18936649056d0.png

 

 

 

 

 

 

 

image.png

Share this post


Link to post

That error message doesn't necessarily mean the specified file can't be found.  It can also mean that a DLL/BPL that the specified file depends on can't be found.  Unfortunately, Windows doesn't differentiate between those two cases.  But what you can do is use a tool like SysInternals Process Monitor to see exactly which file is not being found and where exactly Windows is looking for the file.  That may give you some better clues.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×