qt 代理访问google apps

thinkvd开发日志

由于访问google apps需要用代理,但qt访问google apps数据库时,也需要设置代理,否则对数据库操作没有响应.

代理方式可用soap或rest方式

假设有个网站aaa.appspot.com
QUrl a("aaa.appspot.com");
QNetworkAccessManager *network = new QNetworkAccessManager(this);

QNetworkProxyQuery npq(a);
QList<QNetworkProxy> listOfProxies = QNetworkProxyFactory::systemProxyForQuery(npq);

if (listOfProxies.count() !=0){
    if (listOfProxies.at(0).type() != QNetworkProxy::NoProxy) {
      network->setProxy(listOfProxies.at(0));
      qDebug() << listOfProxies.at(0).hostName();
   }
}

connect(network, SIGNAL(finished(QNetworkReply*)), this, SLOT(outPutPage(QNetworkReply*)));
manager->get(QNetworkRequest(a));

返回时outPutPage中查看是否正确及相应的数据

你可能感兴趣的:(qt 代理访问google apps)