Search code examples
c++qtposthttpsqnetworkaccessmanager

Sending an HTTP request using QNetworkAccessManager


I've got a problem trying to send a request using QNetworkAccessManager from a QObject derived class.

Firstly in my constructor I do the following:

QObject::connect( &mAccessManager, SIGNAL( finished( QNetworkReply* ) ), this, SLOT( requestFinished( QNetworkReply* ) ) );

Then when I wish to send the request I do the following:

QNetworkRequest checkLogin( QUrl( address ) );
checkLogin.setHeader( QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded" );

mByteArray  = QByteArray( "POST \"client\" : oxres" );
QNetworkReply* pReply   = mAccessManager.post( checkLogin, mByteArray );

Now at this point I expect to wait around for a few seconds and then receive a response to my class's slot requestFinished. It doesn't however get called.

I'm at a loss as to what I'm doing wrong. Anyone got any ideas? (I'm sure its something stupidly simple).

Edit: Ok this is very weird. I have wireshark collecting packets in the background and when i generate that post request I see nothing happening in wireshark. So why isn't it sending??

Edit 2: Hmm it seems that the problem lies with me sending a request to an https:// address ... why would that be??


Solution

  • Ok so it turns out the problem is caused byt the fact that Qt does not include SSL support by default.

    http://doc.qt.nokia.com/4.7/ssl.html