我用PHP编写了一个Web服务。我需要通过Web服务URL下载内容。如何从URL下载数据?
需要哪些库?
答案 0 :(得分:5)
在.pro项目文件中添加QT += network
在您的代码中包含以下库:
#include <QUrl>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>
最后通过以下代码接收网址内容:
QString url = "WEB_SERVICE_URL";
QNetworkAccessManager manager;
QNetworkReply *response = manager.get(QNetworkRequest(QUrl(url)));
QEventLoop event;
connect(response, SIGNAL(finished()), &event, SLOT(quit()));
event.exec();
QString content = response->readAll();