Hello,
my problem is i don't get the error message in case something went wrong. In case QNetworkReply::error() != QNetworkReply::NoError all fields are empty. Just
QNetworkReply::errorString provides "Connection closed" or sometimes "Connection refused". But with Wireshark i can see the device/server does indeed send more information including the reason for the "Connection closed".
How can i get the statuscode or description?
{
m_pNetManager = new QNetworkAccessManager(this);
connect(m_pNetManager, &QNetworkAccessManager::finished, this, &MyClass::readReply);
}
MyClass::readReply(QNetworkReply* const pReply)
{
if (pReply->error() != QNetworkReply::NoError)
{
qDebug() << pReply->readAll();
qDebug() << pReply->rawHeaderList();
qDebug() << pReply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
qDebug() << pReply->attribute(QNetworkRequest::RedirectionTargetAttribute);
qDebug() << pReply->errorString() << pReply->error();
pReply->deleteLater();
return;
}
// normal program flow here ...
}
MyClass::MyClass(QObject* parent)
{
m_pNetManager = new QNetworkAccessManager(this);
connect(m_pNetManager, &QNetworkAccessManager::finished, this, &MyClass::readReply);
}
MyClass::readReply(QNetworkReply* const pReply)
{
if (pReply->error() != QNetworkReply::NoError)
{
qDebug() << pReply->readAll();
qDebug() << pReply->rawHeaderList();
qDebug() << pReply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
qDebug() << pReply->attribute(QNetworkRequest::RedirectionTargetAttribute);
qDebug() << pReply->errorString() << pReply->error();
pReply->deleteLater();
return;
}
// normal program flow here ...
}
To copy to clipboard, switch view to plain text mode
Output of above code when receiving an error:
""
()
QVariant(Invalid)
QVariant(Invalid)
"Connection closed" QNetworkReply::NetworkError(RemoteHostClosedError)
On WireShark there are 3 TCP packages [ACK][PSH,ACK][FIN,ACK], the second contains:
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Digest realm="AXIS_WS_ACCC8E7913BD", nonce="oPoxc2iuBQA=1d8e93903510c2de354fadda8b313cd6da6372dc", algorithm=MD5, qop="auth"
Server: gSOAP/2.7
Content-Type: application/soap+xml; charset=utf-8
Content-Length: 620
Connection: close
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Digest realm="AXIS_WS_ACCC8E7913BD", nonce="oPoxc2iuBQA=1d8e93903510c2de354fadda8b313cd6da6372dc", algorithm=MD5, qop="auth"
Server: gSOAP/2.7
Content-Type: application/soap+xml; charset=utf-8
Content-Length: 620
Connection: close
To copy to clipboard, switch view to plain text mode
It seems i only get the content of messages which wiresharks marks as HTTP/XML-Protocol. The above 401 Unauthorized is only in a TCP-Package.
How do i get the "401 Unauthorized"?
Thanks for any ideas.
Bookmarks