PDA

View Full Version : QTcpServer as a HTTPServer + POST Requests



NoRulez
27th May 2008, 14:17
Hey @all,

I'm using QTcpServer as my HTTPServer. When I get a HTTP GET Request all working fine, but how I can handle a HTTP POST Request?

Here is the code where i read from the client:


void HttpServer::readClient() {
if (disabled)
return;

QTcpSocket* socket = (QTcpSocket*)sender();
if (socket->canReadLine()) {
QStringList tokens = QString(socket->readLine()).split(QRegExp("[ \r\n][ \r\n]*"));

qDebug() << "QStringList ---------";
for (QList<QString>::iterator i = tokens.begin(); i != tokens.end(); ++i)
qDebug() << (*i);
}
}


What I see with a GET Request (http://127.0.0.1:84/index.html?firstname=Max&lastname=Mustermann):


QStringList ---------
"GET"
"/index.html?firstname=Max&lastname=Mustermann"
"HTTP/1.1"
""


And here i see something about the POST REQUEST (http://127.0.0.1:84/index.html):


QStringList ---------
"POST"
"/"
"HTTP/1.0"
""


How can i read POST Variables?

Regards
NoRulez

jacek
27th May 2008, 16:10
You just read the first line, but in POST request data comes after the request header.

NoRulez
27th May 2008, 17:49
thanks

currently i wrote:


while (socket->canReadLine()) {

instead of


if (socket->canReadLine()) {

and all will work like a charm :-)

Much thanks and Regards