[Qt-interest] weird problem with QNetworkAccessManager and posting-requests
Benjamin Block
bebl at mageta.org
Sun Apr 24 22:58:21 CEST 2011
Hi guys,
recently I got a really strange problem with the QNetworkAccessManager.
Some times if I do a post-request, the manager sends my post-data twice in
one html-request and additionally sets the tcp-flag fin to 1, although he
should wait for some reply, or not?
The code I use looks almost like this:
netManager = new QNetworkAccessManager(this);
connect(netManager, SIGNAL(finished(QNetworkReply*)), this,
SLOT(replyFinished(QNetworkReply*)));
QNetworkRequest request(QUrl("http://www.scherbenwelten.de/webpage.php"));
request.setRawHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT
6.1; de; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16");
request.setRawHeader("Accept-Charset", "ISO-8859-1");
request.setRawHeader("Accept", "text/html");
request.setRawHeader("Accept-Language", "de-de");
request.setRawHeader("Referer","http://www.scherbenwelten.de/webpagel.php");
request.setAttribute(QNetworkRequest::CookieSaveControlAttribute,
QVariant(true));
request.setHeader(QNetworkRequest::ContentTypeHeader,
QVariant("application/x-www-form-urlencoded"));
QByteArray *user = SWCommunicator::wwwEncodeQString(username);
QByteArray post("SCX=1680&"); // whatever?
post.append("SCY=1050&"); // whatever?
post.append("WSCX=1664&"); // whatever?
post.append("WSCY=875&"); // whatever?
post.append("FORM_USERNAME="+*user+"&");
post.append("LOGON=Login&");
post.append("NOREFRESH=1");
request.setHeader(QNetworkRequest::ContentLengthHeader,
QVariant(QString::number(post.length())));
netManager->post(request, post);
>From what I know, this should be alright. But sometimes the signal
finished() is never sent. So, I thought this might be a network-problem and
traced the tcp-stream with Wireshark.
The first strange thing that I noticed is, that in times where the signal
is not send, the tcp-flags look broken:
[wirshark]
56424 298.006045 192.168.1.4 62.104.23.62 HTTP POST /webpage.php HTTP/1.1
(application/x-www-form-urlencoded)
Transmission Control Protocol, Src Port: 59593 (59593), Dst Port: http
(80), Seq: 673, Ack: 542, Len: 244
Flags: 0x19 (FIN, PSH, ACK)
[/wirshark]
There is no fin-flag set before, so I assume that the
QNetworkAccessManager wants to finish the stream BEFORE getting a reply?!
That seems to be rubbish.
The second thing is, that the post-data are added twice, although the
Content-Length-Field shows the right length:
[wirshark]
POST /webpage.php HTTP/1.1
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.16)
Gecko/20110319 Firefox/3.6.16
Accept-Charset: ISO-8859-1
Accept: text/html
Accept-Language: de-de,de
Referer: http://www.scherbenwelten.de/webpagel.php
Content-Type: application/x-www-form-urlencoded
Content-Length: 92
Connection: Keep-Alive
Accept-Encoding: gzip
Host: www.scherbenwelten.de
SCX=1680&SCY=1050&WSCX=1664&WSCY=875&FORM_USERNAME=Mageta+der+L%F6we&LOGON=Login&NOREFRESH=1SCX=1680&SCY=1050&WSCX=1664&WSCY=875&FORM_USERNAME=Mageta+der+L%F6we&LOGON=Login&NOREFRESH=1
[/wirshark]
In other times everything is fine, the fine-flag is not set and the
post-data only added once.
I do not have concurrent access on the QNetworkAccessManagero-object or
it's child's, so it shouldn't be a race-condition hidden in my code.
Has someone of you a idea why this happens? I do not :(
best regards,
- Ben
Ah, and sry for my bad English.
More information about the Qt-interest-old
mailing list