|
|
2011-04-01
, 07:04
|
|
Posts: 289 |
Thanked: 101 times |
Joined on Oct 2009
|
#2
|
|
|
2011-04-01
, 07:08
|
|
Guest |
Posts: n/a |
Thanked: 0 times |
Joined on
|
#3
|

// this file: mainwindow.cpp
#include "mainwindow.h"
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkRequest>
#include <QUrl>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
leditURL->setText("http://192.168.2.14/index.php");
leditUser->setText("root");
leditPassword->setText("toor");
nam = new QNetworkAccessManager(this);
connect(nam, SIGNAL(finished(QNetworkReply*)), this, SLOT(finishedDownload(QNetworkReply*)));
connect(ui->pbDownload, SIGNAL(clicked()), this, SLOT(downloadXML()));
}
void MainWindow::downloadXML()
{
QByteArray data;
QUrl params;
params.addQueryItem("user", ui->leditUser->text());
params.addQueryItem("pass", ui->leditPassword->text());
data.append(params.toString());
data.remove(0,1);
nam->post(QNetworkRequest(QUrl(leditURL->text())), data);
}
void MainWindow::finishedDownload(QNetworkReply *reply)
{
txtXML->setText(reply->readAll());
}
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
if(checkuser($_POST['user'], $_POST['pass']))
{
echo "<?xml ...";
}
else
{
echo "<p>sorry, wrong auth.</p>";
}
?>
Last edited by XenGi; 2011-04-01 at 06:45.