Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6374097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:26:45+00:00 2026-05-25T01:26:45+00:00

I have kind of a n00b problem, I can’t seem to make HTTP GET

  • 0

I have kind of a n00b problem, I can’t seem to make HTTP GET requests from my Qt Code…

Here is the code supposed to work:

void MainWindow::requestShowPage(){
    QNetworkAccessManager *manager = new QNetworkAccessManager(this);
    connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(requestReceived(QNetworkReply*)));
manager->get(QNetworkRequest(QUrl("http://google.com")));
}

void MainWindow::requestReceived(QNetworkReply* reply){
    QString replyText;
    replyText.fromAscii(reply->readAll());

    ui->txt_debug->appendPlainText(replyText);
}

But the problem is that this just doesn’t work: In requestReceived(QNetworkReply* reply), replyText seems empty, reply->error() returns 0 and reply->errorString() returns “Unknown Error”. I don’t really know what to do right now…

Any idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:26:46+00:00Added an answer on May 25, 2026 at 1:26 am

    There is obviously a redirection, which is not considered as an error.
    You should run a new request with the redirection url provided in the reply attributes until you get the real page:

    void MainWindow::requestReceived(QNetworkReply *reply)
    {
        reply->deleteLater();
    
        if(reply->error() == QNetworkReply::NoError) {
            // Get the http status code
            int v = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
            if (v >= 200 && v < 300) // Success
            {
                 // Here we got the final reply 
                QString replyText = reply->readAll();
                ui->txt_debug->appendPlainText(replyText);
            } 
            else if (v >= 300 && v < 400) // Redirection
            {
                // Get the redirection url
                QUrl newUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
                // Because the redirection url can be relative, 
                // we have to use the previous one to resolve it 
                newUrl = reply->url().resolved(newUrl);
    
                QNetworkAccessManager *manager = reply->manager();
                QNetworkRequest redirection(newUrl);
                QNetworkReply *newReply = manager->get(redirection);
    
                return; // to keep the manager for the next request
            } 
        } 
        else 
        {
            // Error
            ui->txt_debug->appendPlainText(reply->errorString());
        }
    
        reply->manager()->deleteLater();
    }
    

    You should also record where you are redirected or count the number of redirections, to avoid never ending loops.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a kind of basic (but still unresolved) problem. I'm building a program
I have some kind of problem with jQuery selectors. Let's say i want to
I have kind of a tricky Oracle problem. I am trying to select one
I have kind of a unique problem in the project I'm working in. What
Well this kind of n00b question but I still can't figure it out. I
I have kind of a such scenario: (source: microsoft.com ) Here i need to
I have the following LINQ code: var posts = (from p in db.Posts .Include(Site)
I have kind of a tricky problem I'm working on in my current rails
I have a website where a user can send out emails from. I have
I have a Kind Tag with property tagName, and in a html, I code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.