[solved] QNetworkRequest GoogleMaps
-
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)));@
-
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....
-
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. -
Full list of Raw Headers for GoogleMaps:
Location
Content-Type
Set-Cookie
X-Content-Type-Options
Date
Server
Transfer-Encoding
-
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....
-
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.
-
Also when I set RawHeader: @request.setRawHeader("Location", "Ukraine");@ nothing happens.
-
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....
-
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.
-
[quote author="MaximAlien" date="1373384252"]Also when I set RawHeader: @request.setRawHeader("Location", "Ukraine");@ nothing happens.[/quote]
Location is an URL... ты путаеш, это не местонахождение для карты, а ссылка на новый адресс страницы которую ты запросил.
-
Спасибо AcerExtensa!
После того как достал Location после redirect получил HTML страницы GoogleMaps.
Еще раз большое спасибо.