[solved] QNetworkRequest GoogleMaps
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.
@ QNetworkAccessManager *manager = new QNetworkAccessManager(this);
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.
Full list of Raw Headers for GoogleMaps:
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">
The document has moved
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:
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... ты путаеш, это не местонахождение для карты, а ссылка на новый адресс страницы которую ты запросил.
После того как достал Location после redirect получил HTML страницы GoogleMaps.
Еще раз большое спасибо.