使用QNetworkAccessManager发送HTTP请求 [英] Sending an HTTP request using QNetworkAccessManager
问题描述
我有一个问题,尝试使用QNetworkAccessManager从QObject派生类发送请求。
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 );
现在,我希望等待几秒钟,然后收到我班级的回复slot requestFinished。但它不会被调用。
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).
编辑:好的,这很奇怪。我有wireshark在后台收集数据包,当我生成那个帖子请求我看到没有发生在wireshark。那么为什么不发送呢?
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??
编辑2 :似乎问题出在我向https://地址发送请求...为什么是的
Edit 2: Hmm it seems that the problem lies with me sending a request to an https:// address ... why would that be??
推荐答案
确定,结果是,原因是由于Qt不包括默认情况下支持SSL的事实。
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
这篇关于使用QNetworkAccessManager发送HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!