View Full Version : How I get POST variables?

27th March 2009, 11:08

variables from GET method I get without problem

}else if (httpHeader->method() == "GET"){
QUrl* url = new QUrl(httpHeader->path());
QList< QPair<QString, QString> > params = url->queryItems();
QMap<QString, QString> paramsMap;
for(int i=0; i<params.size(); i++){
paramsMap[params[i].first] = params[i].second;

I can work with variables like this: paramsMap["name"]

But I need use the POST method? How I get variables? Help please...

I can only get this:
user-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20070725 Firefox/
accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
accept-language: en-us,en;q=0.5
accept-encoding: gzip,deflate
accept-charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
keep-alive: 300
connection: keep-alive


if(httpHeader->method() == "POST"){
QUrl* url = new QUrl(httpHeader->path());
QList< QPair<QString, QString> > params = httpHeader->values();
for(int i=0; i<params.size(); i++){
out << params[i].first << ": " << params[i].second << endl;

27th March 2009, 12:27
POST data is transmitted after the headers, so looking for it in the header section won't do you any good. You have to wait until the actual data is downloaded, read it and your variables will be there.

27th March 2009, 14:27

Now I have next problem :(

piece of code:

QString header = "";
QString line = clientConnection->readLine();
while(line.length() > 0){
obsah = "";
header += line;
line = clientConnection->readLine();

In header is now:

Host: localhost:8081
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; cs; rv: Gecko/2009021910 Firefox/3.0.7
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: cs,en-us;q=0.7,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: windows-1250,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: localhost/qt/
Content-Type: application/x-www-form-urlencoded
Content-Length: 26


In variable odeslat should be Zaindexuj. Line with variables is maximal 18 chars long. Can anyone help pls?

27th March 2009, 17:19
My guess is you didn't wait until all the data has arrived. Wait for QHttp::requestFinished() signal and then read the data.