I have an http server
server = new httpserver(this);
connect(server,SIGNAL(newConnection()),this,SLOT(newconnection()));
reimplemented incomingConnection so that I can create the socket and read it in a new thread.
void httpserver::incomingConnection( int socketDescriptor ) {
DESCRIPTOR = socketDescriptor;
}
then in newconnection slot:
void serverapp::newconnection() {
processor *process = new processor(server->DESCRIPTOR, this);
connect(process, SIGNAL(finished()), process, SLOT(deleteLater()));
process->start();
}
inside run:
void processor::run() {
QTcpSocket *socket = new QTcpSocket();
socket->setSocketDescriptor(DESCRIPTOR);
socket->waitForReadyRead();
QByteArray text = socket->readAll();
...
}
When I recieve a POST request it sometimes reads all the data, other times not. It only reads the header info and not the actual content:
POST /admin HTTP/1.0
Host: abc.com
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:18.0) Gecko/20100101 Firefox/18.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language: en-ZA,en-GB;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Referer: http://abc.com/admin
Content-Type: application/x-www-form-urlencoded
Content-Length: 64
Connection: keep-alive
NO URL-ENCODED STRING HERE!
But, when I don’t thread it or reimplement tcpserver I get all the data with url-encoded content every time.
QTcpSocket *socket = server->nextPendingConnection();
socket->waitForReadyRead();
QByteArray text = socket->readAll();
print(QString::fromLocal8Bit(text.data(), text.size()));
↧