Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Getting the HTTP standard response code from a QNetworkReply

    General and Desktop
    4
    4
    27169
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      scarleton last edited by

      I am working on some code to get an image from a web server using QNetworkReply. Since there is security to be concerned with, I need to look at the HTTP standard response code to determine if the result is a clean 200 or some type of error. How exactly do I get the the HTTP standard response code?

      1 Reply Last reply Reply Quote 1
      • D
        DenisKormalev last edited by

        Have you tried "error()":http://doc.qt.nokia.com/4.7/qnetworkreply.html#error method?

        1 Reply Last reply Reply Quote 1
        • D
          dangelog last edited by

          The raw response code is available as an integer using the QNetworkReply::attribute(QNetworkRequest::HttpStatusCodeAttribute) method.

          Software Engineer
          KDAB (UK) Ltd., a KDAB Group company

          1 Reply Last reply Reply Quote 2
          • Z
            ZapB last edited by

            Connect a slot up to the QNetworkReply::metaDataChanged() signal. Then in that slot you can check what you need:

            @
            QVariant statusCode = reply->attribute( QNetworkRequest::HttpStatusCodeAttribute );
            if ( !statusCode.isValid() )
            return;

            int status = statusCode.toInt();
            
            if ( status != 200 )
            {
                QString reason = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString();
                qDebug() << reason;
            }
            

            @

            Nokia Certified Qt Specialist
            Interested in hearing about Qt related work

            1 Reply Last reply Reply Quote 2
            • First post
              Last post