码迷,mamicode.com
首页 > Web开发 > 详细

Qt请求http地址数据

时间:2019-11-15 16:56:01      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:http   数据   work   window   array   使用   cti   utf8编码   中文   

 

QNetworkAccessManager *manager = new QNetworkAccessManager(this);;
QNetworkRequest network_request;
QByteArray post_data;

network_request.setUrl(QUrl("http://109.26.149.57:8080/tsinghuaVC/init/selectAllFolder.action"));
network_request.setHeader(QNetworkRequest::UserAgentHeader,"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4098.3 Safari/537.36");

connect(manager, SIGNAL(finished(QNetworkReply*)),this, SLOT(replyFinished(QNetworkReply*)));


//发送请求
manager->get(network_request); 



void replyFinished(QNetworkReply* reply)
{
    QTextCodec *codec = QTextCodec::codecForName("utf8");
    //使用utf8编码,这样才可以显示中文  
    QString all = codec->toUnicode(reply->readAll());
    qDebug() << "= " << all;
    reply->deleteLater();   //最后要释放reply对象
}

 

Qt请求http地址数据

标签:http   数据   work   window   array   使用   cti   utf8编码   中文   

原文地址:https://www.cnblogs.com/herd/p/11867803.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!