QNetworkAccessManger get returns invalid XML as response for few URLs
-
I am using qt - QNetworkAccessManager to read contents from a News portal as shown below
QNetworkReply *reply;
QNetworkAccessManager *network = new QNetworkAccessManager;
network->setNetworkAccessible(QNetworkAccessManager::Accessible);reply = network->get(QNetworkRequest(QUrl("http://news.yahoo.com/rss/sports")));
//Another URL to test "http://news.yahoo.com/rss/baseball"
And the I am trying to read the response as shown below
QString response = reply->readAll();
For few URLs we get proper XML as reply but for few others the XMLs are not proper.
The problem here is - Same URLs for which the XMLs were not well formed works fine everytime showing proper output on desktop browser.
We are able to reproduce this issue with QtSDK/demos/4.7/declarative/rssnews example too if we try to hardcode the above mentioned URL there.
Example for Invalid XML obtained looks something like below : (Proper XML should have title, description tags)
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"><html lang="en" xml:lang="en"><head><title>Sports News Headlines - Yahoo! News</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><style type="text/css">body{color:#353535;background:#ffffff;font-family:Sans-serif}a{color:#006ec2;text-decoration:none}a.z, a.y, a.x, a.w, a.v, .u a{text-decoration:none}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6{padding:0;margin:0}img{border:0}hr{display:none;visibility:hidden;width:0}#page{background:
.............................
.......................................
....................................................
cir0Pb17r9HJLHyL2H6qC_rG"><span>Help</span></a></div><div class="o p ">© 2013 Yahoo! Inc. All rights reserved</div></div></div></div></div><img alt="" src="http://us.bc.yahoo.com/b?P=92jfVTc2LjFqpOI6f__DZQGKMTI1LlFSw2X_m5fY&T=1ehh1jvjf/X=1364378469/E=954001251/R=mi/K=5/V=10.1/W=C/Y=YAHOO/F=1168823538/H=YmVzdC13b2VpZD0iMjI5NTQyMCIgY2Fycmllcj0iSU4tVU5LTk9XTiIgY29udGVudD0ibW9iaWxlX25ld3MiIGR2Y19jbHM9IjQiIHBuPSJ5YWhvb19tb2JpbGVfdXNfd2ViIiBycz0icHJpOnlhaG9vX21vYmlsZV91c193ZWI7c2VjOnlhaG9vO2NycjpJTi1VTktOT1dOOyIgc2VydmVJZD0iOTJqZlZUYzJMakZxcE9JNmZfX0RaUUdLTVRJMUxsRlN3MlhfbTVmWSIgc2l0ZUlkPSI0OTAyNTUxIiB0U3RtcD0iMTM2NDM3ODQ2OTk3MTg3MCIg/Q=-1/I=1/S=1/J=36F70D4C&U=12cle5obm/N=TWHUE2KJiVo-/C=-1/D=WFB2/B=-1/V=0"/> <!-- SpaceID:954001251 --></body></html>
<!-- webgw51.mobile.sp1.yahoo.com uncompressed/chunked Wed Mar 27 10:01:09 GMT 2013 -->
<!-- fe621.global.media.sg3.yahoo.com uncompressed/chunked Wed Mar 27 10:01:09 UTC 2013 --> -
Hi,
you should read data from the reply after finished() signal is emitted ... have you done so?
-
Yes I am reading data only after finished() signal is emitted.