[Interest] Code using QNetworkAccessManager::post() working on Linux but not on Mac

René J. V. Bertin rjvbertin at gmail.com
Sat Aug 26 13:37:44 CEST 2017

Thiago Macieira wrote:

> Was there a request to the server in the first place? Or did QNAM fail without
> sending a request?

I found the explanation after I discovered that one can compare the effective 
request headers with the ones from the reply in the slot that gets called after 
the request has completed.

In the end I had slightly different settings in my filtering proxy on the 2 
machines (Privoxy); connecting now works fine when I don't try to hide the 
referer info. A bit surprising as that information isn't being added as far as I 
can tell...

> Can you check why your HTTP
> server decided to send 403 Forbidden?

I'd love to know how, without having access to it. A packet snooper maybe (never 
used those), to see what's really being exchanged?

> Other recommendations:
> Remove your code that uses QNetworkConfigurationManager. You should always
> assume you're already connected.

Thanks, I was wondering why the code didn't make that assumption indeed. What 
also surprises me is that a wired connection shows up as an invalid 
QNetworkConfiguration and an UnknownAccessibility QNAM capability.

> Replace your QString-based URL construction with QUrlQuery.

I take it you mean the construction of the POST data QByteArray used in the 
QNetworkRequest::post() calls?

I could do

    QUrlQuery postData;
    postData.addQueryItem(QStringLiteral("a"), QStringLiteral("update"));
    postData.addQueryItem(QStringLiteral("s"), KEYDB_SERVER_API);
    postData.addQueryItem(QStringLiteral("p"), KEYDB_ACCESS);
    postData.addQueryItem(QStringLiteral("v"), APPVERSION_STR);
    postData.addQueryItem(QStringLiteral("d"), QString::number(debug));

and then 

	m_netReply = m_accessManager->post(request, postData.toString());


	m_netReply = m_accessManager->post(request, postData.query());

but I don't see the option to obtain the intended encoding and I also doubt if 
this would be an improvement.

This could be nice though:

    QUrlQuery postData = {{QStringLiteral("a"), QStringLiteral("update")},
        , {QStringLiteral("s"), KEYDB_SERVER_API}
        , {QStringLiteral("p"), KEYDB_ACCESS}
        , {QStringLiteral("v"), APPVERSION_STR}
        , {QStringLiteral("d"), QString::number(debug)}};

(or using a << operator) ;)


More information about the Interest mailing list