PDA

View Full Version : How I get POST variables?



emental86
27th March 2009, 11:08
Hello,

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:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6
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

by


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;
}
...

wysota
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.

emental86
27th March 2009, 14:27
Thx...

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:

POST / HTTP/1.1
Host: localhost:8081
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; cs; rv:1.9.0.7) 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

xa=jalsu&odeslat=Z


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

wysota
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.