Reputation: 365
I'm trying to get relay status for ADAM device from my Qt app. Everything seems to be working well if I run the following GET in Postman:
Wireshark shows the trace correctly:
But it does not work from my Qt application. I use QNetworkAccessManager and my code looks like this:
_networkAccessManagerPtr = new QNetworkAccessManager(this);
connect(_networkAccessManagerPtr, SIGNAL(finished(QNetworkReply*)), this, SLOT(ReplyFinished(QNetworkReply*)), Qt::DirectConnection);
SLOT:
void TestClass::ReplyFinished(QNetworkReply *reply)
{
if (reply->error() != QNetworkReply::NoError)
{
qWarning() << "ERROR:" << reply->errorString();
return;
}
}
GET method:
bool TestClass::Get()
{
bool aResult = false;
QString _completeUrl = QString().append("http://").append(_ipAddress.c_str()).append(":").append(QString::number(_port)).append(URL_LOGIN.c_str());
QString _auth = QString().append(_username.c_str()).append(":").append(_password.c_str());
QString _headerData = QString().append("Basic ").append(_auth.toLocal8Bit().toBase64());
_request.setUrl(QUrl(_completeUrl));
_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
_request.setRawHeader("Authorization", _headerData.toLocal8Bit());
QNetworkReply * _replyPtr = _networkAccessManagerPtr->get(_request);
_replyPtr->waitForReadyRead(-1);
aResult = ( _replyPtr->attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt() == 200 );
if ( !aResult )
{
_status = DeviceStatus::DEVICE_UNRESPONSIVE;
qDebug() << _replyPtr->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString();
}
else
{
_status = DeviceStatus::EVERYTHING_OK;
}
_replyPtr->deleteLater();
return aResult;
}
Slot does not work, aResult=false and Wireshark does not show anything and I do not why...
Upvotes: 0
Views: 22