![]() |
Qt http post request
Hi,
I'm developing a Qt program for maemo that should do something similar to filling a html formular, send it via post and download the resulting page (in my case an xml file). I found some code and stuff using google but I'm still a little bit confused about this. Maybe anyone can give me a minimal example? Lets say that is the page ("http://myserver.com/xml.php") that gives me the xml: PHP Code:
|
Re: Qt http post request
I have these two functions for HTTP-get and HTTP-post
void doHttpGet(QString url) { nam->get(QNetworkRequest(QUrl(url))); } void doHttpPost(QString url, QString data) { QByteArray postData; postData.append(data.toAscii()); nam->post(QNetworkRequest(QUrl(url)),postData); } in the constructor I have nam = new QNetworkAccessManager(this); connect(nam,SIGNAL(finished(QNetworkReply*)),this, SLOT(finished(QNetworkReply*))); void Network::finished(QNetworkReply *reply) { if(reply->error() == QNetworkReply::NoError) { //then you use this function wich will make you get a bytearray with the xml file byteArray = reply->readAll(); } } |
Re: Qt http post request
That sounds quite simple. Thanks for your advice, I will test it later and post the results here. :)
Only one question: What should "QString data" be? Something like "user=root;pass=toor"? EDIT: I found it myself. Now everything works fine. Thanks for the help. If somebody has the same Issue here is a small example showing the "right" way: Code:
// this file: mainwindow.cpp |
All times are GMT. The time now is 09:24. |
vBulletin® Version 3.8.8