本文整理汇总了C++中QNetworkAccessManager::setCookieJar方法的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkAccessManager::setCookieJar方法的具体用法?C++ QNetworkAccessManager::setCookieJar怎么用?C++ QNetworkAccessManager::setCookieJar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QNetworkAccessManager
的用法示例。
在下文中一共展示了QNetworkAccessManager::setCookieJar方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setupBrowser
void OwncloudShibbolethCredsPage::setupBrowser()
{
if (!_browser.isNull()) {
return;
}
OwncloudWizard *ocWizard = qobject_cast<OwncloudWizard *>(wizard());
AccountPtr account = ocWizard->account();
// we need to reset the cookie jar to drop temporary cookies (like the shib cookie)
// i.e. if someone presses "back"
QNetworkAccessManager *qnam = account->networkAccessManager();
CookieJar *jar = new CookieJar;
jar->restore(account->cookieJarPath());
// Implicitly deletes the old cookie jar, and reparents the jar
qnam->setCookieJar(jar);
_browser = new ShibbolethWebView(account);
connect(_browser.data(), &ShibbolethWebView::shibbolethCookieReceived,
this, &OwncloudShibbolethCredsPage::slotShibbolethCookieReceived, Qt::QueuedConnection);
connect(_browser.data(), &ShibbolethWebView::rejected,
this, &OwncloudShibbolethCredsPage::slotBrowserRejected);
_browser->move(ocWizard->x(), ocWizard->y());
_browser->show();
_browser->setFocus();
}
示例2: 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*)));
}
示例3: testGetRequest
void testGetRequest()
{
QString url = "http://m.baidu.com/s?word=abc&ts=1223145&rq=ab";
QNetworkAccessManager* networkAccessManager = new QNetworkAccessManager();
QNetworkRequest request;
request.setUrl(QUrl(url));
request.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
//request.setRawHeader("Accept-Encoding", "gzip, deflate, sdch");
request.setRawHeader("Accept-Language", "h-CN,zh;q=0.8");
request.setRawHeader("Host", "m.baidu.com");
request.setRawHeader("Referer", "http://m.baidu.com");
request.setRawHeader("Connection", "keep-alive");
request.setRawHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36");
QNetworkReply* reply = networkAccessManager->get(request);
QEventLoop loop;
NetWorkCookieJar* cookieJar = new NetWorkCookieJar(networkAccessManager);
networkAccessManager->setCookieJar(cookieJar);
QTimer timer;
timer.setSingleShot(true);
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
timer.start(5000);
loop.exec();
timer.stop();
qDebug() << request.rawHeaderList();
qDebug() << reply->readAll();
qDebug() << cookieJar->getCookies();
networkAccessManager->deleteLater();
reply->deleteLater();
}
示例4: getFavoriteThreads
void HeadlessApplication::getFavoriteThreads() {
// list green + yellow flags
const QUrl url(DefineConsts::FORUM_URL + "/forum1f.php?owntopic=1");
qDebug() << "getFavoriteThreads()";
CookieJar *cookies = new CookieJar();
cookies->loadFromDisk();
QNetworkAccessManager *accessManager = new QNetworkAccessManager();
accessManager->setCookieJar(cookies);
QNetworkRequest request(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
QSslConfiguration sslConfig = request.sslConfiguration();
sslConfig.setPeerVerifyMode(QSslSocket::VerifyNone);
sslConfig.setPeerVerifyDepth(1);
sslConfig.setProtocol(QSsl::TlsV1);
sslConfig.setSslOption(QSsl::SslOptionDisableSessionTickets, true);
QNetworkReply* reply = accessManager->get(request);
bool ok = connect(reply, SIGNAL(finished()), this, SLOT(checkReplyFav()));
Q_ASSERT(ok);
Q_UNUSED(ok);
}
示例5: icon
LxMainWindow::LxMainWindow( QWidget* prarent /*= 0*/ )
:QWebView(prarent)
{
_initWidget();
this->setRenderHints(QPainter::SmoothPixmapTransform | QPainter::HighQualityAntialiasing);
QObject::connect(this, SIGNAL(linkClicked(const QUrl&)), this, SLOT(linkClickedAction(const QUrl&)));
QNetworkAccessManager* pNetworkAccessManager = this->page()->networkAccessManager();
LxOption* pOption = lxCoreApp->getOption();
if (pOption && pNetworkAccessManager)
{
QString strCookies = pOption->getCookieFilePath();
LxNetWorkCookies* pCookies = new LxNetWorkCookies(strCookies, this);
pNetworkAccessManager->setCookieJar(pCookies);
QNetworkDiskCache *diskCache = new QNetworkDiskCache(this);
QString location = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
//QString location = QDesktopServices::storageLocation(QDesktopServices::CacheLocation);
diskCache->setCacheDirectory(location);
diskCache->setMaximumCacheSize(1024);//byte
pNetworkAccessManager->setCache(diskCache);
pNetworkAccessManager->setNetworkAccessible(QNetworkAccessManager::Accessible);
m_bLoadHrefInCurrent = pOption->getLoadHrefInCurrentMainDialog();
}
QString iconName = pOption->getSystemTrayIconName();
QString iconPath = QCoreApplication::applicationDirPath() + "/" + iconName;
qDebug("show path %s", qPrintable(iconPath));
QIcon icon(iconPath);
this->setWindowIcon(icon);
}
示例6: QDialog
ShibLoginDialog::ShibLoginDialog(const QUrl& url, QWidget *parent)
: QDialog(parent),
url_(url)
{
setWindowTitle(tr("Login with Shibboleth"));
setWindowIcon(QIcon(":/images/seafile.png"));
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
QVBoxLayout *vlayout = new QVBoxLayout();
setLayout(vlayout);
webview_ = new QWebView;
vlayout->addWidget(webview_);
CustomCookieJar *jar = new CustomCookieJar(this);
QNetworkAccessManager *mgr = webview_->page()->networkAccessManager();
mgr->setCookieJar(jar);
connect(mgr, SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError>&)),
this, SLOT(sslErrorHandler(QNetworkReply*, const QList<QSslError>&)));
connect(jar, SIGNAL(newCookieCreated(const QUrl&, const QNetworkCookie&)),
this, SLOT(onNewCookieCreated(const QUrl&, const QNetworkCookie&)));
webview_->load(url_);
}
示例7: create
QNetworkAccessManager* TBNetworkAccessManagerFactory::create(QObject *parent)
{
QMutexLocker lock(&mutex);
Q_UNUSED(lock);
QNetworkAccessManager* manager = new TBNetworkAccessManager(parent);
#ifdef Q_OS_SYMBIAN
bool useDiskCache = Utility::Instance()->qtVersion() >= 0x040800;
#else
bool useDiskCache = true;
#endif
if (useDiskCache){
QNetworkDiskCache* diskCache = new QNetworkDiskCache(parent);
QString dataPath = QDesktopServices::storageLocation(QDesktopServices::CacheLocation);
QDir dir(dataPath);
if (!dir.exists()) dir.mkpath(dir.absolutePath());
diskCache->setCacheDirectory(dataPath);
diskCache->setMaximumCacheSize(3*1024*1024);
manager->setCache(diskCache);
}
QNetworkCookieJar* cookieJar = TBNetworkCookieJar::GetInstance();
manager->setCookieJar(cookieJar);
cookieJar->setParent(0);
return manager;
}
示例8: children
QNetworkReply * Pillow::ElasticNetworkAccessManager::createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *outgoingData)
{
// Find the first available child QNetworkAccessManager.
QNetworkAccessManager* nam = NULL;
foreach (QObject* child, children())
{
if ((nam = qobject_cast<QNetworkAccessManager*>(child)))
{
if (nam->children().size() < 6)
break; // Found an available one.
else
nam = NULL; // This one is not available.
}
}
if (nam == NULL)
{
// Did not find an available manager. Spawn a new one.
nam = new QNetworkAccessManager(this);
if (cookieJar())
{
nam->setCookieJar(cookieJar());
cookieJar()->setParent(0);
}
}
return static_cast<NamOpener*>(nam)->doCreateRequest(op, request, outgoingData);
}
示例9: QNetworkAccessManager
QNetworkAccessManager*
QMLNetFactory::create(QObject *parent)
{
QNetworkAccessManager *nam = new QNetworkAccessManager(parent);
nam->setCookieJar(new WebKitCookieJar);
return nam;
}
示例10: create
QNetworkAccessManager* ACNetworkAccessManagerFactory::create(QObject *parent)
{
QMutexLocker lock(&mutex);
Q_UNUSED(lock);
QNetworkAccessManager* manager = new ACNetworkAccessManager(parent);
QNetworkCookieJar* cookieJar = ACNetworkCookieJar::GetInstance();
manager->setCookieJar(cookieJar);
cookieJar->setParent(0);
return manager;
}
示例11: main
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QNetworkRequest req;
QUrl *login_url = new QUrl("https://www.secure.pixiv.net/login.php?return_to=%2F");
req.setUrl(*login_url);
req.setHeader(QNetworkRequest::UserAgentHeader, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36");
req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
QNetworkAccessManager man;
QNetworkCookieJar *cookies = new QNetworkCookieJar();
man.setCookieJar(cookies);
QByteArray *data = new QByteArray();
data->append("mode=login&return_to=http%3A%2F%2Fwww.pixiv.net%2F&pixiv_id=beta168921%40gmail.com&pass=xjy168921&skip=1");
QNetworkReply *reply = man.post(req,*data);
QObject::connect(reply,&QNetworkReply::finished, [&reply, &man](){
QTextStream qerr(stderr);
QList<QNetworkReply::RawHeaderPair> headers(reply->rawHeaderPairs());
for (int i = 0; i < headers.size(); ++i)
{
qerr << "HEADER: " << headers[i].first << " CONTENT: " << headers[i].second << "\n";
}
// man(reply->manager());
// qerr << "\n\n";
// QList<QNetworkCookie> cookie(man->cookieJar()->cookiesForUrl(QUrl("http://www.pixiv.net")));
// for (int i = 0; i > cookie.size(); ++i) {
// qerr << cookie[i].toRawForm();
// }
// qerr << man.cookieJar()->cookiesForUrl(QUrl("http://www.pixiv.net"));
});
// QTextStream qerr(stderr);
return a.exec();
}
示例12: shib_login_url
ShibLoginDialog::ShibLoginDialog(const QUrl& url,
const QString& computer_name,
QWidget *parent)
: QDialog(parent),
url_(url),
cookie_seen_(false)
{
setWindowTitle(tr("Login with Shibboleth"));
setWindowIcon(QIcon(":/images/seafile.png"));
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
QVBoxLayout *vlayout = new QVBoxLayout();
setLayout(vlayout);
webview_ = new QWebView;
vlayout->addWidget(webview_);
CustomCookieJar *jar = new CustomCookieJar(this);
QNetworkAccessManager *mgr = webview_->page()->networkAccessManager();
NetworkManager::instance()->addWatch(mgr);
mgr->setCookieJar(jar);
connect(mgr, SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError>&)),
this, SLOT(sslErrorHandler(QNetworkReply*, const QList<QSslError>&)));
connect(jar, SIGNAL(newCookieCreated(const QUrl&, const QNetworkCookie&)),
this, SLOT(onNewCookieCreated(const QUrl&, const QNetworkCookie&)));
QUrl shib_login_url(url_);
QString path = shib_login_url.path();
if (!path.endsWith("/")) {
path += "/";
}
path += "shib-login";
shib_login_url.setPath(path);
webview_->load(::includeQueryParams(
shib_login_url, ::getSeafileLoginParams(computer_name, "shib_")));
}