PDA

View Full Version : HTTP POST method



Macok
24th July 2010, 12:39
I have a problem with a HTTP post method.

Here's an example:
Go to http://www.ddo.com/, type "BLABLA" in search area and press ENTER.
You will get "Total: 0 Results found for "BLABLA"".

I want to reach the same effect using Qt, I tried this:
void MainWindow::on_pushButton_clicked()
{
http=new QHttp("www.ddo.com");
connect(http, SIGNAL(readyRead(QHttpResponseHeader)), this, SLOT(readResponse(QHttpResponseHeader)));
http->post("/component/search/", "searchword=BLABLA");
}

void MainWindow::readResponse(QHttpResponseHeader header){
qDebug()<<http->readAll();
}
http->readAll() returns source code of site http://www.ddo.com/component/search/, but in source this expression:
Total: 0 Results found for "BLABLA"
doesn't exist. Instead, there's:
Total: 0 Results found for ""

So it looks like server didn't receive any post data.
I tried this on more websites, and every time server ignores my post data.

What's wrong?

Thanks in advance!

squidge
24th July 2010, 15:56
Use a network sniffer and see what is different between your implementation and a web browsers.

Macok
24th July 2010, 19:29
I captured packets sent by internet browser and my program by WinDump, and everything was the same, except some values from HTTP header.

Now I used QNetworkAccessManager instead of QHttp and it works, but i don't know why :P

squidge
24th July 2010, 22:42
So the data sent is exactly the same as before, as verified by WinDump?

Macok
25th July 2010, 12:21
Data are the same, but header is quiet different (QNetworkAccessManager sends also information about User-Agent etc.).

squidge
25th July 2010, 14:33
Right, so you do know why. The header is different!