Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QNetworkReply results in "Connection closed"
Qt 6.11 is out! See what's new in the release blog

QNetworkReply results in "Connection closed"

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.7k Views 1 Watching
  • 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.
  • P Offline
    P Offline
    Priya_sipl
    wrote on last edited by
    #1

    Hello Friends,

    I want to get page source of the url requested.

    I used code as:

    @ /* create QNetworkAccessManager obj
    * to send network requests and receive replies*/
    QNetworkAccessManager* objNetAccessManager = new QNetworkAccessManager(this);

        /* Connect signal slot for getting page source of requested url */
        connect(objNetAccessManager, SIGNAL(finished(QNetworkReply*)),this,     SLOT(getPageSource(QNetworkReply*)));
    
        try
        {
            QNetworkRequest req;
            req.setUrl(QUrl(url));
    
    
            /* for getting data and headers of requesrt sent */
            QNetworkReply *reply = objNetAccessManager->get(req);
    
            connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
                    this, SLOT(slotError(QNetworkReply::NetworkError)));
            connect(reply, SIGNAL(sslErrors(QList<QSslError>)),
                    this, SLOT(slotSslErrors(QList<QSslError>)));
    
    
            /* QNetworkReply and related classes are asynchronous and
             * doesn’t offer a blocking API and
             * requires an event loop to be running.
             * We enter a local QEventLoop, and when the reply has finished,
             * the local event loop quits. */
            QEventLoop loop;
            connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
            loop.exec&#40;&#41;;
    
           // this->thread()->sleep(3);
        }
        catch(std::exception &e)
        {
            qFatal("Error %s sending event ",e.what() );
        }
    

    getPageSource(QNetworkReply* reply)
    {
    //*Get pageSource from requested URL//
    QString pageSource = QString::fromUtf8(reply->readAll());
    }
    @

    But I am getting pageSource as "Connection closed".
    or
    "Error downloading http://... - server replied: Not Acceptable"

    Please help me to resolve this.

    Pinnacle_cool

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved