POST request from curl example
-
Hi,
I got example the request like below:curl --request POST \ --url https://demo1.vnetlpr.pl/api/events/search \ --header 'Accept: application/json' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data public_key=01932182-8a75-7238-9b04-e969bcb9e9e6 \ --data 'hash=MD5( public_key + private_key )' \
do I prepared the same code like above but in in qt ?
QNetworkRequest request; request.setUrl(QUrl("https://demo1.vnetlpr.pl/api/events/search")); request.setRawHeader("Accept", "application/json"); request.setRawHeader("Content-Type", "application/x-www-form-urlencoded"); QJsonObject obj; obj["public_key"] = (QString)publicKey; obj["hash"]= (QString)QCryptographicHash::hash(publicKey + privateKey, QCryptographicHash::Md5); QNetworkReply *reply = manager.post(request, QJsonDocument(obj).toJson());
-
You're right. The request body it doesn't in JSON notation.
I rewrote my code like below:
QNetworkRequest request; request.setUrl(QUrl("https://demo1.vcn.pl/api/events/search")); request.setRawHeader("Accept", "application/json"); request.setRawHeader("Content-Type", "application/x-www-form-urlencoded"); QByteArray md5 = QCryptographicHash::hash(publicKey + privateKey, QCryptographicHash::Md5); auto ba = QByteArray("public_key="+publicKey+"&hash="+md5); QNetworkReply *reply = manager.post(request,ba);
Now is the same what in example in the first post ?
-
Hi, the .setRawHeader()s look ok but QJson? I don't see any colons etc. in the curl example, the --data lines seem to be vanilla params, so try something like:
auto ba = QByteArray("public_key=01932182-8a75-7238-9b04-e969bcb9e9e6&hash=MD5( public_key + private_key )"); QNetworkReply *reply = manager.post(request, ba);
-
Hi,
I got example the request like below:curl --request POST \ --url https://demo1.vnetlpr.pl/api/events/search \ --header 'Accept: application/json' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data public_key=01932182-8a75-7238-9b04-e969bcb9e9e6 \ --data 'hash=MD5( public_key + private_key )' \
do I prepared the same code like above but in in qt ?
QNetworkRequest request; request.setUrl(QUrl("https://demo1.vnetlpr.pl/api/events/search")); request.setRawHeader("Accept", "application/json"); request.setRawHeader("Content-Type", "application/x-www-form-urlencoded"); QJsonObject obj; obj["public_key"] = (QString)publicKey; obj["hash"]= (QString)QCryptographicHash::hash(publicKey + privateKey, QCryptographicHash::Md5); QNetworkReply *reply = manager.post(request, QJsonDocument(obj).toJson());
Hi,
@Damian7546 said in POST request from curl example:
obj["public_key"] = (QString)publicKey;
obj["hash"]= (QString)QCryptographicHash::hash(publicKey + privateKey, QCryptographicHash::Md5);Beside the good points made by @hskoglund, this is pretty wrong. You can't type cast a QByteArray as a QString like that.
-
You're right. The request body it doesn't in JSON notation.
I rewrote my code like below:
QNetworkRequest request; request.setUrl(QUrl("https://demo1.vcn.pl/api/events/search")); request.setRawHeader("Accept", "application/json"); request.setRawHeader("Content-Type", "application/x-www-form-urlencoded"); QByteArray md5 = QCryptographicHash::hash(publicKey + privateKey, QCryptographicHash::Md5); auto ba = QByteArray("public_key="+publicKey+"&hash="+md5); QNetworkReply *reply = manager.post(request,ba);
Now is the same what in example in the first post ?
-
This post is deleted!
-
Did you check the server logs ?
Did you connect the reply errorOccured and sslErrors signals ? -
-
@SGaist working! Tahnks for help.
-
What did you do to fix the problem ?
-
@SGaist In Ubuntu (where I developing my app) I had a problem with ssl, and below solution fixed my problem:
https://forum.qt.io/topic/144102/qsslsocket-failure-from-online-installer-version-ubuntu/8And added to *.pro file:
LIBS += -L/opt/openssl-1.1.1q -lcrypto LIBS += -L/opt/openssl-1.1.1q -lssl
I have no idea how to run it on my destinatiom machine based on Debian System ....
To generate file to my destination machine I use CQtDeployer , which one generate below directories:
but inside I do not see any files related with ssl.@SGaist What can I do ?
-
@SGaist In Ubuntu (where I developing my app) I had a problem with ssl, and below solution fixed my problem:
https://forum.qt.io/topic/144102/qsslsocket-failure-from-online-installer-version-ubuntu/8And added to *.pro file:
LIBS += -L/opt/openssl-1.1.1q -lcrypto LIBS += -L/opt/openssl-1.1.1q -lssl
I have no idea how to run it on my destinatiom machine based on Debian System ....
To generate file to my destination machine I use CQtDeployer , which one generate below directories:
but inside I do not see any files related with ssl.@SGaist What can I do ?
@Damian7546 you don't . You have to deploy the libraries along with your application.
-
@Damian7546 you don't . You have to deploy the libraries along with your application.
@SGaist hmm... but I do not know how....
-
@SGaist hmm... but I do not know how....
@Damian7546 Start by looking at the alternatives mentioned in https://forum.qt.io/topic/154740/where-is-linuxdeployqt
-
@Damian7546 Start by looking at the alternatives mentioned in https://forum.qt.io/topic/154740/where-is-linuxdeployqt
@JonB I Use CQtDeployer.
I am currently using two options:
cqtdeployer -bin -qmlDir
To add libs from my .pro file :
LIBS += -L/opt/openssl-1.1.1q -lcrypto
LIBS += -L/opt/openssl-1.1.1q -lsslWhich one options I should add ? -libDir or -extraLibs ?
-
@JonB I Use CQtDeployer.
I am currently using two options:
cqtdeployer -bin -qmlDir
To add libs from my .pro file :
LIBS += -L/opt/openssl-1.1.1q -lcrypto
LIBS += -L/opt/openssl-1.1.1q -lsslWhich one options I should add ? -libDir or -extraLibs ?
I copied dictionary with ssl library to my qt project location:
.../Lib/openssl-1.1.1q
And changed the *.pro file to:
LIBS += -L$$PWD/Lib/openssl-1.1.1q/ -lcrypto
LIBS += -L$$PWD/Lib/openssl-1.1.1q/ -lsslApplication works , when is runnig form qt creator . But when I run without qt creator it doesnt work ...
-
I copied dictionary with ssl library to my qt project location:
.../Lib/openssl-1.1.1q
And changed the *.pro file to:
LIBS += -L$$PWD/Lib/openssl-1.1.1q/ -lcrypto
LIBS += -L$$PWD/Lib/openssl-1.1.1q/ -lsslApplication works , when is runnig form qt creator . But when I run without qt creator it doesnt work ...
@Damian7546
Assuming by "doesnt work" you mean you are told it cannot find the OpenSSL shared libraries at runtime.Then the implication is that the environment/search path is somehow different from Creator than without. E.g. check your
LD_LIBRARY_PATH
.From a terminal try running
ldd
on your executable. Does that show it requiring certain*.so
files which cannot be found?I believe the OpenSSL runtime provides some runtime
openssl.so
(or whatever name) file(s). Find these.I copied dictionary with ssl library to my qt project location:
That may be enough for linking, but I don't think it is for locating the
.so
files at runtime under Linux. Unless they are picked up off theRPATH
which was linked into the program. -
@Damian7546
Assuming by "doesnt work" you mean you are told it cannot find the OpenSSL shared libraries at runtime.Then the implication is that the environment/search path is somehow different from Creator than without. E.g. check your
LD_LIBRARY_PATH
.From a terminal try running
ldd
on your executable. Does that show it requiring certain*.so
files which cannot be found?I believe the OpenSSL runtime provides some runtime
openssl.so
(or whatever name) file(s). Find these.I copied dictionary with ssl library to my qt project location:
That may be enough for linking, but I don't think it is for locating the
.so
files at runtime under Linux. Unless they are picked up off theRPATH
which was linked into the program.@JonB Now work!
I copied from: ..../Lib/openssl-1.1.1q below files:
libcrypto.so
libcrypto.so.1.1
libssl.so
libssl.so.1.1to my deployed application
It look like by default, an SSL library are dynamically loads any installed OpenSSL library at run-time.
-
Yes, by default Qt builds dlopens OpenSSL.