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,
@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 ?
-
@Damian7546 you don't . You have to deploy the libraries along with your application.
-
@Damian7546 Start by looking at the alternatives mentioned in https://forum.qt.io/topic/154740/where-is-linuxdeployqt