当前位置: 首页>>代码示例>>C++>>正文


C++ QNetworkAccessManager::setProxy方法代码示例

本文整理汇总了C++中QNetworkAccessManager::setProxy方法的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkAccessManager::setProxy方法的具体用法?C++ QNetworkAccessManager::setProxy怎么用?C++ QNetworkAccessManager::setProxy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QNetworkAccessManager的用法示例。


在下文中一共展示了QNetworkAccessManager::setProxy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getUpdateFlist

QByteArray AutoUpdater::getUpdateFlist()
{
    QByteArray flist;

    QNetworkAccessManager *manager = new QNetworkAccessManager;
    manager->setProxy(Settings::getInstance().getProxy());
    QNetworkReply* reply = manager->get(QNetworkRequest(QUrl(flistURI)));
    while (!reply->isFinished())
    {
        if (abortFlag)
            return flist;
        qApp->processEvents();
    }

    if (reply->error() != QNetworkReply::NoError)
    {
        qWarning() << "getUpdateFlist: network error: " + reply->errorString();
        reply->deleteLater();
        manager->deleteLater();
        return flist;
    }

    flist = reply->readAll();
    reply->deleteLater();
    manager->deleteLater();

    return flist;
}
开发者ID:13983441921,项目名称:qTox,代码行数:28,代码来源:autoupdate.cpp

示例2: getUpdateFile

AutoUpdater::UpdateFile AutoUpdater::getUpdateFile(UpdateFileMeta fileMeta,
                                        std::function<void(int,int)> progressCallback)
{
    UpdateFile file;
    file.metadata = fileMeta;

    QNetworkAccessManager *manager = new QNetworkAccessManager;
    manager->setProxy(Settings::getInstance().getProxy());
    QNetworkReply* reply = manager->get(QNetworkRequest(QUrl(filesURI+fileMeta.id)));
    QObject::connect(reply, &QNetworkReply::downloadProgress, progressCallback);
    while (!reply->isFinished())
    {
        if (abortFlag)
            return file;
        qApp->processEvents();
    }

    if (reply->error() != QNetworkReply::NoError)
    {
        qWarning() << "getUpdateFile: network error: " + reply->errorString();
        reply->deleteLater();
        manager->deleteLater();
        return file;
    }

    file.data = reply->readAll();
    reply->deleteLater();
    manager->deleteLater();

    return file;
}
开发者ID:13983441921,项目名称:qTox,代码行数:31,代码来源:autoupdate.cpp

示例3: process

void KDSoapThreadTask::process(QNetworkAccessManager& accessManager)
{
    // Can't use m_iface->asyncCall, it would use the accessmanager from the main thread
    //KDSoapPendingCall pendingCall = m_iface->asyncCall(m_method, m_message, m_action);

    //Headers should be always qualified
    for (KDSoapHeaders::Iterator it = m_data->m_headers.begin(); it != m_data->m_headers.end(); ++it) {
        it->setQualified(true);
    }

#if QT_VERSION >= 0x040700
    QNetworkCookieJar* jar = m_data->m_iface->d->accessManager()->cookieJar();
    // Qt-4.6: this aborts in setParent(this) because the jar is from another thread
    // Qt-4.7: it's from a different thread, so this won't change the parent object
    accessManager.setCookieJar(jar);
#endif

    accessManager.setProxy( m_data->m_iface->d->accessManager()->proxy() );

    QBuffer* buffer = m_data->m_iface->d->prepareRequestBuffer(m_data->m_method, m_data->m_message, m_data->m_headers);
    QNetworkRequest request = m_data->m_iface->d->prepareRequest(m_data->m_method, m_data->m_action);
    QNetworkReply* reply = accessManager.post(request, buffer);
    m_data->m_iface->d->setupReply(reply);
    KDSoapPendingCall pendingCall(reply, buffer);

    KDSoapPendingCallWatcher *watcher = new KDSoapPendingCallWatcher(pendingCall, this);
    connect(watcher, SIGNAL(finished(KDSoapPendingCallWatcher*)),
            this, SLOT(slotFinished(KDSoapPendingCallWatcher*)));
}
开发者ID:hporten,项目名称:KDSoap,代码行数:29,代码来源:KDSoapClientThread.cpp

示例4: sendBlockingNetRequest

bool Utils::sendBlockingNetRequest(const QUrl& theUrl, QString& reply)
{
    QNetworkAccessManager manager;
    QEventLoop q;
    QTimer tT;

    manager.setProxy(M_PREFS->getProxy(QUrl("http://merkaartor.be")));

    tT.setSingleShot(true);
    connect(&tT, SIGNAL(timeout()), &q, SLOT(quit()));
    connect(&manager, SIGNAL(finished(QNetworkReply*)),
            &q, SLOT(quit()));

    QNetworkReply *netReply = manager.get(QNetworkRequest(theUrl));

    tT.start(M_PREFS->getNetworkTimeout());
    q.exec();
    if(tT.isActive()) {
        // download complete
        tT.stop();
    } else {
        return false;
    }

    reply = netReply->readAll();
    return true;
}
开发者ID:4x4falcon,项目名称:fosm-merkaartor,代码行数:27,代码来源:Utils.cpp

示例5: makeJsonRequest

QByteArray Toxme::makeJsonRequest(QString url, QString json, QNetworkReply::NetworkError &error)
{
    if (error)
        return QByteArray();

    QNetworkAccessManager netman;
    netman.setProxy(Settings::getInstance().getProxy());
    QNetworkRequest request{url};
    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
    QNetworkReply* reply = netman.post(request,json.toUtf8());

    while (!reply->isFinished())
    {
        QThread::msleep(1);
        qApp->processEvents();
    }

    error = reply->error();
    if (error)
    {
        qWarning() << "makeJsonRequest: A network error occured:" << reply->errorString();
        return QByteArray();
    }

    return reply->readAll();
}
开发者ID:1KoT1,项目名称:qTox,代码行数:26,代码来源:toxme.cpp

示例6: exec

QByteArray QWget::exec(QUrl url, QByteArray postData)
{
    QNetworkAccessManager * manager = network_manager();
    manager->setProxy(_proxy);
    connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(onFinished(QNetworkReply*)));
    QNetworkRequest * nr = new QNetworkRequest(url);
    //nr->setRawHeader("User-Agent","Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1");
    nr->setRawHeader("User-Agent","Opera/9.0");
    qDebug() << url;

    finished = false;
    if(postData.isNull())
        manager->get(*nr);
    else
        manager->post(*nr,postData);
    while(!finished)
    {
        QCoreApplication::instance()->processEvents();
        #ifdef WIN32
        Sleep(50);
        #else
            usleep(50000);
        #endif
    }
    delete nr;
    QCoreApplication::instance()->processEvents();
    //qDebug() << "Ans: " << ans;
    // delete nr;
    return ans;
    return QByteArray();
}
开发者ID:trousev,项目名称:qwget,代码行数:31,代码来源:qwget.cpp

示例7: newManager

QNetworkAccessManager* newManager(QObject* parent)
{
	QNetworkAccessManager* netman = new QNetworkAccessManager(parent);
	if(Options::instance()->useProxy()) {
		netman->setProxy(Options::instance()->getProxy());
	}

	return netman;
}
开发者ID:FlorianFieber,项目名称:psi-plus-plugins,代码行数:9,代码来源:common.cpp

示例8: proxy

QNetworkAccessManager *MyNetworkAccessManagerFactory::create(QObject *parent)
{
    QNetworkAccessManager *nam = new QNetworkAccessManager(parent);
    if (!proxyHost.isEmpty()) {
        qDebug() << "Created QNetworkAccessManager using proxy" << (proxyHost + ":" + QString::number(proxyPort));
        QNetworkProxy proxy(QNetworkProxy::HttpCachingProxy, proxyHost, proxyPort);
        nam->setProxy(proxy);
    }

    return nam;
}
开发者ID:SchleunigerAG,项目名称:WinEC7_Qt5.3.1_Fixes,代码行数:11,代码来源:main.cpp

示例9: updateFromInternet

//ダウンロードしてアップデートする
void FavoriteMenu::updateFromInternet(bool force)
{
    QFileInfo fi(FAVORITE_DOWNLOAD_FILE);
    if(!force && (fi.lastModified().addDays(1) >= QDateTime::currentDateTime())){
        //更新期間すぎてないのでなにもしない
//        qDebug() << "don't update, last modify+2days=" << fi.lastModified().addDays(2)
//                 << ", today=" << QDateTime::currentDateTime();
        return;
    }
    qDebug() << "start download";
    QNetworkAccessManager *net = new QNetworkAccessManager(this);
    connect(net, &QNetworkAccessManager::finished, [this](QNetworkReply *reply) {
        if(reply->error() == QNetworkReply::NoError){
            QFile file(FAVORITE_DOWNLOAD_FILE);
            if(file.open(QIODevice::WriteOnly)){
                file.write(reply->readAll());
                file.close();
                //通知
                emit downloadFinished();
            }
        }
    });
    //プロキシ
    QSettings settings(QSettings::IniFormat, QSettings::UserScope, KANMEMO_PROJECT, KANMEMO_NAME);
    QNetworkProxy *proxy = new QNetworkProxy();
    bool enable = settings.value(SETTING_GENERAL_PROXY_ENABLE, false).toBool();
    QString host = settings.value(SETTING_GENERAL_PROXY_HOST).toString();
    if(host.length() > 0 && enable){
        proxy->setType(QNetworkProxy::HttpProxy);
        proxy->setHostName(host);
        proxy->setPort(settings.value(SETTING_GENERAL_PROXY_PORT, 8888).toInt());
        net->setProxy(*proxy);
    }else{
        net->setProxy(QNetworkProxy::NoProxy);
    }
    net->get(QNetworkRequest(FAVORITE_DOWNLOAD_URL));
}
开发者ID:hermit4,项目名称:KanmusuMemory,代码行数:38,代码来源:favoritemenu.cpp

示例10: run

void ProxyCheckThread::run()
{
	QNetworkAccessManager *manager = new QNetworkAccessManager();
	manager->setProxy(proxy);
	QNetworkRequest request = QNetworkRequest(QUrl("http://www.google.com"));
	request.setRawHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.0; WOW64) AppleWebKit/534.27+ (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27");
	QNetworkReply *reply = manager->get(request);

	QEventLoop loop;
	connect(manager, SIGNAL(finished(QNetworkReply *)), &loop, SLOT(quit()));
	loop.exec();
	QByteArray data = reply->readAll();
	result = data.contains("<title>Google</title>");
	delete reply;
	delete manager;
}
开发者ID:Fatze,项目名称:browserext,代码行数:16,代码来源:proxycheckthread.cpp

示例11: getServerPubkey

QByteArray Toxme::getServerPubkey(QString url, QNetworkReply::NetworkError &error)
{
    if (error)
        return QByteArray();

    // Get key
    QNetworkAccessManager netman;
    netman.setProxy(Settings::getInstance().getProxy());
    QNetworkRequest request{url};
    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
    QNetworkReply* reply = netman.get(request);

    while (!reply->isFinished())
    {
        QThread::msleep(1);
        qApp->processEvents();
    }

    error = reply->error();
    if (error)
    {
        qWarning() << "getServerPubkey: A network error occured:" << reply->errorString();
        return QByteArray();
    }

    // Extract key
    static const QByteArray pattern{"key\":\""};

    QString json = reply->readAll();
    delete reply;
    json = json.remove(' ');
    int start = json.indexOf(pattern) + pattern.length();
    int end = json.indexOf("\"", start);
    int pubkeySize = (end - start) / 2;
    QString rawKey = json.mid(start, pubkeySize*2);

    QByteArray key;
    // I think, exist more easy way to convert key to ByteArray
    for (int i = 0; i < pubkeySize; i++) {
        QString byte = rawKey.mid(i*2, 2);
        key[i] = byte.toInt(nullptr, 16);
    }

    return key;
}
开发者ID:Artom-Kozincev,项目名称:qTox,代码行数:45,代码来源:toxme.cpp

示例12: checkUserPassword

/**
*	@brief Check wether the user password is correct
*
*	@see 	signal authentificationResponse(bool response)
*
*	@param  QString userName			the user name
*	@param  QString userPassword		the user password
*/
void ImageShackUploader::checkUserPassword(QString	userName    ,
        QString  userPassword)
{
    QUrl url = QUrl(authentificationUrl + "?username=" + userName + "&password=" + userPassword + "&nocookie=1&format=xml");

    QNetworkRequest request(url);
    QNetworkAccessManager * manager = new QNetworkAccessManager;

    this->uploadAborted = false;

    // manage proxy
    if(this->proxy != NULL)
        manager->setProxy(*this->proxy);

    this->networkReply = manager->get(request);

    connect(this->networkReply, SIGNAL(error(QNetworkReply::NetworkError)),
            this , SLOT(manageUploadError(QNetworkReply::NetworkError)));

    connect(this->networkReply, SIGNAL(finished()), this, SLOT(manageAuthentificationResponse()));
}
开发者ID:Supm4n,项目名称:ImageShackUploader,代码行数:29,代码来源:ImageShackUploader.cpp

示例13: dlg

  std::pair<QNetworkReply::NetworkError, QString> NetworkProxyDialog::testProxyConnection(const QNetworkProxy &t_proxy, QWidget *t_parent)
  {
    QProgressDialog dlg("Verifying Proxy Connection", "Cancel",0, 1000, t_parent);
    dlg.setWindowModality(Qt::WindowModal);
    dlg.setValue(0);
    dlg.setMinimumDuration(1000);

    QNetworkAccessManager nam;
    nam.setProxy(t_proxy);
    QNetworkReply *head = nam.head(QNetworkRequest(QUrl("https://bcl.nrel.gov/")));

    if (!head) return std::make_pair(QNetworkReply::UnknownNetworkError, QString("Unknown error creating connection to proxy."));

    boost::posix_time::ptime start = boost::posix_time::microsec_clock::universal_time();
    while ( !head->isFinished()
            && (boost::posix_time::microsec_clock::universal_time() - start).total_milliseconds() < 10000
            && !dlg.wasCanceled())
    {
      int time = (boost::posix_time::microsec_clock::universal_time() - start).total_milliseconds();
      dlg.setValue(time);
      if (time >= 950 && dlg.maximum() < 10000)
      {
        dlg.setMaximum(10000);
      }
    }
    dlg.reset();
    Application::instance().processEvents();

    head->deleteLater();

    if (!head->isFinished()) 
    {
      head->abort();
      return std::make_pair(QNetworkReply::TimeoutError, QString("Timed out while attempting to verify proxy connection"));
    }

    LOG(Debug, " errorString from proxy test " << toString(head->errorString()) << " " << head->error());

    return std::make_pair(head->error(), head->errorString());
  }
开发者ID:CUEBoxer,项目名称:OpenStudio,代码行数:40,代码来源:NetworkProxyDialog.cpp

示例14: QObject

UpdateChecker::UpdateChecker(QObject* parent_) : QObject(parent_){
	setObjectName("UpdateChecker");
    QNetworkAccessManager* networkManager = new QNetworkAccessManager(this);
    connect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(finished(QNetworkReply*)));
    
	//Proxy Settings
	Settings settings;
	if(settings.getProxyEnable()){
		QNetworkProxy proxy;
		proxy.setType(QNetworkProxy::HttpProxy);
		proxy.setHostName(settings.getProxyAddress());
		proxy.setPort(settings.getProxyPort());
		if(settings.getProxyAuthentification()){
			proxy.setUser(settings.getProxyUser());
			proxy.setPassword(settings.getProxyPassword());
		}
		networkManager->setProxy(proxy);
	}
	
	//qDebug() << networkManager->proxy().hostName();
	//qDebug() << networkManager->proxy().port();
	
	networkManager->get(QNetworkRequest(QUrl(_downloadsUrl)));
}
开发者ID:jzsun,项目名称:raptor,代码行数:24,代码来源:UpdateChecker.cpp

示例15: sendImage

/**
*	Upload an image. This method is called by
*	userUploadImage and anonymousUploadImage
*	methods
*
*	@access public
*/
void ImageShackUploader::sendImage(ImageShackObject * imageToUpload ,
                                   QHash<QString, QString>   headers)
{
    QString   imagePath = imageToUpload->getObjectPath();
    QFile     image(imagePath);
    QFileInfo imageInfos(imagePath);

    QNetworkAccessManager * manager = new QNetworkAccessManager;
    QNetworkRequest         request(this->imageUploadUrl);

    QByteArray boundary   = "IMAGESHACKUPLOADER";
    QByteArray cr         = "\r\n";

    QByteArray data;

    if(!image.open(QIODevice::ReadOnly))
    {
        if(uploadAborted==false)
        {
            emit uploadError(ImageShackError::FailedOpeningTheFile);
            this->abortUploads();
        }

        return;
    }

    // build of the header
    data.append("--" + boundary + cr);
    data.append("Content-Disposition: form-data; ");
    data.append( "name=\"fileupload\"; filename=\"" + imageInfos.absoluteFilePath() + "\";" + cr);
    data.append("Content-Type: " + this->mimeType(imagePath) + cr + cr);

    // insertion of the image
    data.append(image.readAll() + cr);

    image.close();

    // build the footer
    QHashIterator<QString, QString> h(headers);
    while (h.hasNext())
    {
        h.next();

        data.append("--" + boundary + cr);
        data.append("Content-Disposition: form-data; ");
        data.append("name=\"" + h.key() + "\"" + cr + cr);
        data.append(h.value() + cr);
    }

    data.append("--" + boundary + "--" + cr);

    request.setHeader(QNetworkRequest::ContentTypeHeader, "multipart/form-data; boundary=" + boundary);
    request.setHeader(QNetworkRequest::ContentLengthHeader, QString::number(data.size()).toAscii());

    // manage proxy
    if(this->proxy != NULL)
        manager->setProxy(*this->proxy);

    this->fileBeingUploaded = imageToUpload;

    //this->uploadsProcessing	   = true;

    timeoutTimer->start(TIMEOUT);

    this->networkReply = manager->post(request, data);

    connect(this->networkReply, SIGNAL(finished())      ,
            this        , SLOT  (imageUploaded()));

    connect(this->networkReply, SIGNAL(error(QNetworkReply::NetworkError))       ,
            this        , SLOT  (manageUploadError(QNetworkReply::NetworkError)));

    connect(this->networkReply, SIGNAL(uploadProgress(qint64,qint64)),
            this	    , SLOT  (manageUploadProgress(qint64,qint64)));

    connect(manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
            this   , SLOT  (manageAuthentificationRequired(QNetworkReply*,QAuthenticator*)));

    connect(manager, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)),
            this   , SLOT  (manageProxyAuthentificationRequired(QNetworkProxy,QAuthenticator*)));
}
开发者ID:Supm4n,项目名称:ImageShackUploader,代码行数:88,代码来源:ImageShackUploader.cpp


注:本文中的QNetworkAccessManager::setProxy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。