[Interest] Code using QNetworkAccessManager::post() working on Linux but not on Mac
René J.V. Bertin
rjvbertin at gmail.com
Fri Aug 25 15:05:15 CEST 2017
Hi,
I'm porting a Qt5-based little downloader from MS Windows to Mac+Linux (both have Qt 5.8.0). It uses a POST operation to authenticate with the server, using code that works fine on MSWin and Linux. On Mac, I keep getting a Forbidden reply from the server (the MSWin executable functions fine under Wine, though...)
The request is set up like this::
QNetworkAccessManager *accessManager = new QNetworkAccessManager(this);
QNetworkConfigurationManager configurationManager;
{ QEventLoop loop;
loop.connect(&configurationManager, SIGNAL(updateCompleted()), SLOT(quit()));
emit messageLog(tr("Check API: updating network configuration info"));
configurationManager.updateConfigurations();
// wait for the update to run.
loop.exec();
emit messageLog(tr("Check API: network configuration info updated"));
}
QNetworkConfiguration defaultNetworkConfiguration = configurationManager.defaultConfiguration();
if (defaultNetworkConfiguration.isValid()) {
accessManager->setConfiguration(defaultNetworkConfiguration);
}
QString dataToEncode = QString("a=%1&s=%2&p=%3&v=%4&d=%5")
.arg("update").arg(KEYDB_SERVER_API).arg(KEYDB_ACCESS).arg(APPVERSION_STR).arg(debug);
QByteArray data = QUrl::toPercentEncoding(dataToEncode, "&=");
QNetworkRequest request;
request.setUrl(QUrl(KEYDB_SERVER));
request.setRawHeader("Referer", QStringLiteral("Updater %1").arg(APPVERSION_STR).toLatin1());
request.setRawHeader("User-Agent", QByteArrayLiteral("XXX"));
request.setRawHeader("Content-Type", QByteArrayLiteral("application/x-www-form-urlencoded; charset=UTF-8"));
m_netReply = accessManager->post(request, data);
connect(m_netReply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(handleApiReplyError(QNetworkReply::NetworkError)));
connect(m_netReply, SIGNAL(sslErrors(const QList<QSslError>&)), SLOT(handleSslErrors(const QList<QSslError>&)));
connect(m_netReply, SIGNAL(finished()), SLOT(handleApiReplyFinished()));
connect(m_netReply, SIGNAL(readyRead()), SLOT(handleApiReplyRead()));
Is there anything in this code that is wrong (or missing)? Is it possible to see more of the actual communication with the server, e.g. to compare the actual request headers (in case the server is rejecting Macs, for instance)?
Thanks,
René
More information about the Interest
mailing list