CURL Request -> HTTP Post equivalent (solved)
I want to connect my QT-Project to a API.
the API CURL call is :
"curl -X POST -u username:password https://my.fastbill.com/api/1.0/api.php"
I Only want to use QT-Libs thats why i tried it with following Code
QNetworkAccessManager* manager = new QNetworkAccessManager(this);
network_reply = manager->post(request,postData);
I can connect to the server this way but the reply alsways is "wrong userdata".
So i tried various ways to fix this for example:
But not a single one of them works.
Can you tell me what I'm doing wrong or how to make this Call with the Help of QT-Libs?
Hi and welcome to devnet,
Unless I misunderstood, you might be interested by "this":http://doc.qt.io/qt-5/qnetworkaccessmanager.html#authenticationRequired
Hope it helps
Fastbill expects the Content-Type to be set to application/xml And the POST body to be an XML request. You are not sending a valid XML request, hence the error message about the body. (It also accepts a Json formatted request)
Thats not the problem. If I send the equal Curl command via my Linux Terminal as told in the api ->
"curl -X POST -u username:apikey https://my.fastbill.com/api/1.0/api.php"
the response is that there’s actually no Content. But the login worked!
And exactly this result is what I want to accomplish with QT-Libs.
@SGaist, thx I will have a look at it!
I now solved the problem....
Its about the Signal written in the documentation - ChrisW67 sent us the link to.
There are 2 Possibility’s:
Do it via the Signal
Set a Header to the QNetworkRequest:
@QString concatenated = username + ":" + password;
QByteArray data = concatenated.toLocal8Bit().toBase64();
QString headerData = "Basic " + data;
Thx again and a happy new year!