关于获取网页字符串的问题求助
https://passport.baidu.com/v2/api/?getapi&class=login&tpl=mn&tangram=true
比如我想获取这个网页的token后面的字符串,我写的代码如下:
inline QString get_tiebapage(QString url)
{
QNetworkAccessManager *manager = new QNetworkAccessManager();
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url)));
QByteArray responseData;
QEventLoop eventLoop;
connect(manager, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
eventLoop.exec(); //block until finish
responseData = reply->readAll();
return QString(responseData);
}
debug了一下 获取的字符串为空 求解高人
[解决办法]
应该是出错啦:
int _httpcode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
int _errcode = reply->error();
[解决办法]
responseData为空,就说明数据没有返回,怎么取里面的数据,肯定你的程序执行出错了,看_httpcode与_errcode返回值判断是啥问题.