Making HTTP POST request in Qt with Meego 1.2 Harmattan
Here's the situation - I attach some file (JPEG image) to the HTTP POST request so it should be sent to the local server via Wi-Fi and server should return some result (simple text).
Here's the problem I faced doing this in my Qt-application for Nokia N9 (Meego 1.2 Harmattan).
After request is sent, proceed by the server and answer is sent back (I can see log on the server) there's a huge delay (about 1 min) before data from server reaches the handset. If answer returns in several parts - the delay is befor开发者_StackOverflowe first part and others are getting very fast (as it should be with the first one too).The same code I use in the same app for Symbian^3 (Symbian Anna) on Nokia C6-01 and it works just fine - all the data returns in a couple of seconds (tested in the same network with the same server and request). Also I have several GET requests sending from this app to the same server and all of them works fine too. So it might be the only Meego problem.
Snippets:
void PostDownloader::sendPostJpgImage(QString url, QImage image) {
if(mainReply)
return;
char boundary[] = "AyV04a234DsHeKHcvNds";
image = image.convertToFormat(QImage::Format_RGB888);
QByteArray body;
QBuffer buffer(&body);
buffer.open(QIODevice::WriteOnly);
image.save(&buffer, "JPG");
buffer.close();
QByteArray b;
b.append("--").append(boundary).append("\r\n");
b.append("Content-Disposition: form-data; name=\"jpgfile\"; filename=\"camera\"\r\n");
b.append("Content-Type: image/jpeg\r\n");
b.append("\r\n");
b.append(body);
b.append("\r\n");
b.append("--").append(boundary).append("--");
QNetworkRequest req = QNetworkRequest(QUrl(url));
req.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QString("multipart/form-data; boundary=")+boundary));
req.setHeader(QNetworkRequest::ContentLengthHeader, QString::number(b.size()));
req.setRawHeader("Connection", "Close");
req.setRawHeader("Cache-Control", "no-cache");
req.setRawHeader("Keep-Alive", "1");
mainReply = manager->post(req, b); //POST
connect(mainReply, SIGNAL(readyRead()), this, SLOT(dataReceived()));
connect(mainReply, SIGNAL(finished()), this, SLOT(finished()));
}
So the delay is before calling the dataReceived() slot. How can this can be solved? What can you advice?
Thanks in advance.
精彩评论