本文整理汇总了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;
}
示例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;
}
示例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*)));
}
示例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;
}
示例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();
}
示例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();
}
示例7: newManager
QNetworkAccessManager* newManager(QObject* parent)
{
QNetworkAccessManager* netman = new QNetworkAccessManager(parent);
if(Options::instance()->useProxy()) {
netman->setProxy(Options::instance()->getProxy());
}
return netman;
}
示例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;
}
示例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));
}
示例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;
}
示例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;
}
示例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()));
}
示例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());
}
示例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)));
}
示例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*)));
}