Solved connectToHostEncrypted: TLS initialization failed
-
I tried to make a request for a free API.
t is very simple.
And i got an error:connectToHostEncrypted: TLS initialization failed
It's my first time doing this. I will really appriciate if you please can help me to fix it .
QNetworkAccessManager mMananger; QUrlQuery query; query.addQueryItem("page", "2");
//declaracion de la URL por parte
QUrl urlPage;
urlPage.setScheme("https");
urlPage.setHost("reqres.in"); /
urlPage.setPath("/api/users");
urlPage.setQuery(query);QNetworkRequest mRequest; mRequest.setUrl(urlPage); //almacena la respuesta QNetworkReply * mReply= mMananger.get(mRequest); QObject::connect(mReply,&QNetworkReply::finished,[&](){ QMetaEnum metaEnum = QMetaEnum::fromType<QNetworkReply::NetworkError>(); qDebug() << "Error" << metaEnum.valueToKey(mReply->error()); QByteArray read =mReply->readAll(); std::cout << "Got response:\n" <<read.toStdString()<<std::endl; mReply->close(); mReply->deleteLater(); });```
I am using Qt5.15.2 MSCV2019 de 64bits OS Window10 Thank you
-
Thank you very much for all your answers.
I took the easy way using maintenance tool.
and it worked very well -
Hi and welcome to devnet,
Did you forgot to install OpenSSL ?
-
hi, thanks for answering, I am new in this.
How can i do that?i follow the solution of someone else and I already tried to solve it but it is too old.
i downloaded the installer from
Web Site
and selected de option for 64 bits for developersafter that i included in the .pro file:
LIBS += -LC:/Program Files/OpenSSL-Win64/lib -lubsec INCLUDEPATH += C:/OpenSSL-Win64/include
and then in the main file
#include <openssl/aes.h>
but still doesn´t work i looked in the folder lib and i didn´t see a file named ubsec.lib
-
You can get OpenSSL through Qt's installer.
You also have to make she the compiler used to build it matches the one you are using.It's a C library, so you are safe compiler wise.
-
Hi @Ana_Ichi.
You can read an extensive entry here https://forum.qt.io/topic/95700/qsslsocket-tls-initialization-failed.
It seems kind of funny because there are so many answers through time. Anyway, this works for me, you can test it in Windows:
1. Install OpenSSL from Maintenance Tool.
2. Independently of your compiler, go to C:\Qt\Tools\OpenSSL\Win_x64\bin (if you have 64 bits application).
3. Copy libcrypto-1_1-x64.dll and libssl-1_1-x64.dll and paste in your release or debug application executable.
Cheers,
-
@Ana_Ichi said in connectToHostEncrypted: TLS initialization failed:
LIBS += -LC:/Program Files/OpenSSL-Win64/lib -lubsec
I think you will need quotes around that path.
-
Thank you very much for all your answers.
I took the easy way using maintenance tool.
and it worked very well