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. [solved] QNetworkRequest GoogleMaps
Forum Updated to NodeBB v4.3 + New Features

[solved] QNetworkRequest GoogleMaps

Scheduled Pinned Locked Moved General and Desktop
11 Posts 2 Posters 4.4k 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.
  • M Offline
    M Offline
    MaximAlien
    wrote on last edited by
    #1

    Hello,

    I have a problem loading GoogleMaps webpage using QNetworkAccessManager, QNetworkRequest and QNetworkReply classes. Moreover it was working well a few weeks ago. So the problem is that I receive empty HTML of webpage. Also QNetworkReply::NetworkError doesn't show any errors and when I track downloadProgress it says that bytesTotal is 0.

    Shall I add any settings in my request? Or there are some SSL issues? Maybe you have the same problem I faced? What would you suggest? Any help is appreciated.

    Sample code:
    @ QNetworkAccessManager *manager = new QNetworkAccessManager(this);
    QUrl url("http://maps.google.com/maps/");

    QNetworkRequest request(url);
    QNetworkReply *reply = manager->get(request);
    
    connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(slotFinished(QNetworkReply*)));
    connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(slotError(QNetworkReply::NetworkError)), Qt::UniqueConnection);
    connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(slotDownloadProgress(qint64,qint64)));@
    
    1 Reply Last reply
    0
    • A Offline
      A Offline
      AcerExtensa
      wrote on last edited by
      #2

      If you call HTTP://maps.google.com/maps/ you will actually redirected to HTTPS://maps.google.com/maps, so it is possible what you have troubles with SSL. Check for SSL errors, also check headers in response if you don't get any http error....

      God is Real unless explicitly declared as Integer.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MaximAlien
        wrote on last edited by
        #3

        Thank for your reply AcerExtensa.

        I checked SSL errors and there are none. Also I found list of RawHeaders. There is one header called "Set-Cookie". Maybe I need to use cookies here? What do you think?

        Thank you,
        Maxim.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MaximAlien
          wrote on last edited by
          #4

          Full list of Raw Headers for GoogleMaps:

          Location

          Content-Type

          Set-Cookie

          X-Content-Type-Options

          Date

          Server

          Transfer-Encoding

          1 Reply Last reply
          0
          • A Offline
            A Offline
            AcerExtensa
            wrote on last edited by
            #5

            I think Location it is exactly what you need. Where should be a redirect link... also check HTTP response code in your finished slot, I don't think it is 200....

            God is Real unless explicitly declared as Integer.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MaximAlien
              wrote on last edited by
              #6

              HTTP response code is 302.

              The only thing I don't understand is when I load Google and use link "http://www.google.com/":http://www.google.com/ it returns at least HTML where you can find tag with redirection link:
              @<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
              <TITLE>301 Moved</TITLE></HEAD><BODY>
              <H1>301 Moved</H1>
              The document has moved
              <A HREF="http://www.google.com/">here</A>.
              </BODY></HTML>@

              Please advice.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                MaximAlien
                wrote on last edited by
                #7

                Also when I set RawHeader: @request.setRawHeader("Location", "Ukraine");@ nothing happens.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  AcerExtensa
                  wrote on last edited by
                  #8

                  Your redirection link is in the header named "Location".
                  maybe google have forget to add custom site for 302 redirect, or something else.... HTTP 302 redirection do not requires any kind of html or something else to be send as response. Valid redirect consist only of 2 lines:

                  @
                  HTTP/1.1 302
                  Location: http://www.iana.org/domains/example/
                  @

                  Anything else is custom additions....

                  God is Real unless explicitly declared as Integer.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    AcerExtensa
                    wrote on last edited by
                    #9

                    You need to read "Location" header, the url to which you should redirect is saved there....

                    In your finished slot, read raw headers from QNetworkReply, find header named "Location" or "location" read value from it and make new request with the value as an url adress.

                    God is Real unless explicitly declared as Integer.

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      AcerExtensa
                      wrote on last edited by
                      #10

                      [quote author="MaximAlien" date="1373384252"]Also when I set RawHeader: @request.setRawHeader("Location", "Ukraine");@ nothing happens.[/quote]

                      Location is an URL... ты путаеш, это не местонахождение для карты, а ссылка на новый адресс страницы которую ты запросил.

                      God is Real unless explicitly declared as Integer.

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        MaximAlien
                        wrote on last edited by
                        #11

                        Спасибо AcerExtensa!

                        После того как достал Location после redirect получил HTML страницы GoogleMaps.

                        Еще раз большое спасибо.

                        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