[Qt-interest] Corrupted data with QTcpSocket

Esdras Beleza listas at esdrasbeleza.com
Wed Jan 18 20:59:10 CET 2012


Hi,

I have to communicate with a server using sockets and fetch some data that
are URL-encoded. One of them is a URL value. It can assume two forms:

- A simple URL, like http://www.google.com, that comes as "http%3A%2F%
2Fwww.google.com"
- A URL containing another URL for redirection, like
http://www.someurl.com/foo?bar=http%3A%2F%2Fwww.redirecttohere.com, that
comes as http%3A%2F%2Fwww.someurl.com%2Ffoo%3Fbar%3Dhttp%253A%252F%
252Fwww.redirecttohere.com

In the second case (and only in it), when I fetch the data using
QTcpSockets, the data seems to be corrupted. When QTcpSocket
reads http%3A%2F%2Fwww.someurl.com%2Ffoo%3Fbar%3Dhttp%253A%252F%
252Fwww.redirecttohere.com , it puts some characters in some places of the
string and breaks the URL encoding.

Using a Telnet connection I can get the right values. When I use QTcpSocket
to fetch the data it gets corrupted with some non-printing characters that
break the correct decoding.

My readyData() signal is processed with this slot:

void ConnectionHandler::readReply() {
    QByteArray serverReplyArray;
    while (socket->canReadLine()) {
        serverReplyArray.append(socket->readLine().trimmed());
    }

    if (!serverReplyArray.isEmpty()) {
        emit serverReply(serverReplyArray);
    }
}


Any tip?


Esdras

--
formulageek.com.br
esdrasbeleza.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20120118/02ec5142/attachment.html 


More information about the Qt-interest-old mailing list