本文整理汇总了C++中QNetworkCookieJar类的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkCookieJar类的具体用法?C++ QNetworkCookieJar怎么用?C++ QNetworkCookieJar使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QNetworkCookieJar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cookies
String cookies(const Document* document, const KURL& url)
{
NetworkingContext* context = networkingContext(document);
if (!context)
return String();
QNetworkCookieJar* jar = context->networkAccessManager()->cookieJar();
QUrl urlForCookies(url);
QUrl firstPartyUrl(document->firstPartyForCookies());
if (!thirdPartyCookiePolicyPermits(context, urlForCookies, firstPartyUrl))
return String();
QList<QNetworkCookie> cookies = jar->cookiesForUrl(urlForCookies);
if (cookies.isEmpty())
return String();
QStringList resultCookies;
foreach (const QNetworkCookie& networkCookie, cookies) {
if (networkCookie.isHttpOnly())
continue;
resultCookies.append(QString::fromLatin1(networkCookie.toRawForm(QNetworkCookie::NameAndValueOnly).constData()));
}
return resultCookies.join(QLatin1String("; "));
}
示例2: cookies
String cookies(const Document* document, const KURL& url)
{
QUrl u(url);
#if QT_VERSION >= 0x040400
QNetworkCookieJar* jar = cookieJar(document);
if (!jar)
return String();
QList<QNetworkCookie> cookies = jar->cookiesForUrl(u);
if (cookies.isEmpty())
return String();
QStringList resultCookies;
foreach (QNetworkCookie networkCookie, cookies) {
#if QT_VERSION >= 0x040500
if (networkCookie.isHttpOnly())
continue;
#endif
resultCookies.append(QString::fromAscii(
networkCookie.toRawForm(QNetworkCookie::NameAndValueOnly).constData()));
}
return resultCookies.join(QLatin1String("; "));
#else
QString cookies = QCookieJar::cookieJar()->cookies(u);
int idx = cookies.indexOf(QLatin1Char(';'));
if (idx > 0)
cookies = cookies.left(idx);
return cookies;
#endif
}
示例3: QNetworkAccessManager
NetworkAccessManager::NetworkAccessManager(QObject *parent) :
QNetworkAccessManager(parent)
{
QNetworkCookieJar* cookieJar = NetworkCookieJar::GetInstance();
setCookieJar(cookieJar);
cookieJar->setParent(0);
}
示例4: setCredentials
void Account::setCredentials(AbstractCredentials *cred)
{
// set active credential manager
QNetworkCookieJar *jar = 0;
if (_am) {
jar = _am->cookieJar();
jar->setParent(0);
_am->deleteLater();
}
if (_credentials) {
credentials()->deleteLater();
}
// The order for these two is important! Reading the credential's
// settings accesses the account as well as account->_credentials
_credentials = cred;
cred->setAccount(this);
_am = _credentials->getQNAM();
if (jar) {
_am->setCookieJar(jar);
}
connect(_am, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)),
SLOT(slotHandleErrors(QNetworkReply*,QList<QSslError>)));
connect(_credentials, SIGNAL(fetched()),
SLOT(slotCredentialsFetched()));
}
示例5: adjust_title
void MainWindow::finished_loading(bool ok)
{
if(!ok)
std::cout << "LOAD FINISH NOT OK!\n\n";
QString output;
QWebElement body;
progress = 100;
adjust_title();
QWebFrame *frame = uimw->webView->page()->mainFrame();
QWebElement document = frame->documentElement();
QWebElement element = document.firstChild();
while(!element.isNull())
{
if(element.tagName() == "BODY")
{
output = element.toInnerXml();
if(output == "ok\n")
{
QNetworkCookieJar *cj = uimw->webView->page()->networkAccessManager()->cookieJar();
QList<QNetworkCookie> cookies = cj->cookiesForUrl(testauth);
for(QList<QNetworkCookie>::const_iterator i = cookies.begin() ; i != cookies.end() ; i++ )
{
std::cout << "Set-Cookie: ";
QByteArray ba = i->toRawForm();
std::cout.write(ba.data(), ba.count());
std::cout << "\r\n";
}
exit(0);
}
}
element = element.nextSibling();
}
this->show();
}
示例6: lock
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;
}
示例7: handleUnsupportedContent
void YafOAuth::handleUnsupportedContent(QNetworkReply *reply)
{
if (reply->error() == QNetworkReply::NoError) {
return;
}
QString url = reply->url().toString();
if(url.contains("webmounter://token#access_token="))
{
m_token = Data::RegExp::getByPattern("webmounter://token#access_token=(.*)&state", url);
QNetworkCookieJar *cookie = m_view->page()->networkAccessManager()->cookieJar();
QUrl yafUrl ("https://oauth.yandex.ru");
QString login;
for (int i=0; i < cookie->cookiesForUrl(yafUrl).count(); i++)
{
if (cookie->cookiesForUrl(yafUrl).at(i).name() == "yandex_login")
{
login = cookie->cookiesForUrl(yafUrl).at(i).value();
break;
}
}
delete m_view;
m_view = NULL;
emit authFinished(eNO_ERROR, login, m_token);
}
}
示例8: removeDomainCookies
void CookiesContentsWidget::removeDomainCookies()
{
const QModelIndexList indexes = m_ui->cookiesView->selectionModel()->selectedIndexes();
if (indexes.isEmpty())
{
return;
}
QNetworkCookieJar *cookieJar = NetworkManagerFactory::getCookieJar();
QList<QNetworkCookie> cookies;
for (int i = 0; i < indexes.count(); ++i)
{
QStandardItem *domainItem = ((indexes.at(i).isValid() && indexes.at(i).parent() == m_model->invisibleRootItem()->index()) ? findDomain(indexes.at(i).sibling(indexes.at(i).row(), 0).data(Qt::ToolTipRole).toString()) : m_model->itemFromIndex(indexes.at(i).parent()));
if (domainItem)
{
for (int j = 0; j < domainItem->rowCount(); ++j)
{
QStandardItem *cookieItem = domainItem->child(j, 0);
if (cookieItem)
{
const QNetworkCookie cookie = getCookie(cookieItem->index());
if (!cookies.contains(cookie))
{
cookies.append(cookie);
}
}
}
}
}
if (cookies.isEmpty())
{
return;
}
QMessageBox messageBox;
messageBox.setWindowTitle(tr("Question"));
messageBox.setText(tr("You are about to delete %n cookies.", "", cookies.count()));
messageBox.setInformativeText(tr("Do you want to continue?"));
messageBox.setIcon(QMessageBox::Question);
messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
messageBox.setDefaultButton(QMessageBox::Yes);
if (messageBox.exec() == QMessageBox::Yes)
{
for (int i = 0; i < cookies.count(); ++i)
{
cookieJar->deleteCookie(cookies.at(i));
}
}
}
示例9: cookie
void AccessManager::setRawCookie(const QByteArray &rawCookie, const QUrl &url)
{
QNetworkCookie cookie(rawCookie.left(rawCookie.indexOf('=')),
rawCookie.mid(rawCookie.indexOf('=')+1));
qDebug() << Q_FUNC_INFO << cookie.name() << cookie.value();
QList<QNetworkCookie> cookieList;
cookieList.append(cookie);
QNetworkCookieJar *jar = cookieJar();
jar->setCookiesFromUrl(cookieList, url);
}
示例10: removeCookies
void CookiesContentsWidget::removeCookies()
{
const QModelIndexList indexes = m_ui->cookiesView->selectionModel()->selectedIndexes();
if (indexes.isEmpty())
{
return;
}
QNetworkCookieJar *cookieJar = NetworkManagerFactory::getCookieJar();
QList<QNetworkCookie> cookies;
for (int i = 0; i < indexes.count(); ++i)
{
if (!indexes.at(i).isValid())
{
continue;
}
if (indexes.at(i).data(Qt::UserRole).toString().isEmpty())
{
QStandardItem *domainItem = m_model->itemFromIndex(indexes.at(i));
if (!domainItem)
{
continue;
}
for (int j = 0; j < domainItem->rowCount(); ++j)
{
QStandardItem *cookieItem = domainItem->child(j, 0);
if (cookieItem)
{
cookies.append(getCookie((cookieItem->index())));
}
}
}
else
{
QStandardItem *cookieItem = m_model->itemFromIndex(indexes.at(i));
if (cookieItem)
{
cookies.append(getCookie(cookieItem->index()));
}
}
}
for (int i = 0; i < cookies.count(); ++i)
{
cookieJar->deleteCookie(cookies.at(i));
}
}
示例11: lock
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;
}
示例12: testCorrectHttpHeader
void testCorrectHttpHeader()
{
HttpServerThread server(countryResponse(), HttpServerThread::Public);
KDSoapClientInterface client(server.endPoint(), countryMessageNamespace());
KDSoapAuthentication auth;
auth.setUser(QLatin1String("kdab"));
auth.setPassword(QLatin1String("unused"));
client.setAuthentication(auth); // unused...
QNetworkCookieJar myJar;
QList<QNetworkCookie> myCookies;
myCookies.append(QNetworkCookie("biscuits", "are good"));
myJar.setCookiesFromUrl(myCookies, QUrl(server.endPoint()));
client.setCookieJar(&myJar);
QByteArray expectedRequestXml = expectedCountryRequest();
client.setSoapVersion(KDSoapClientInterface::SOAP1_1);
{
KDSoapMessage ret = client.call(QLatin1String("getEmployeeCountry"), countryMessage());
// Check what we sent
QVERIFY(xmlBufferCompare(server.receivedData(), expectedRequestXml));
QVERIFY(!ret.isFault());
QCOMPARE(server.header("Content-Type").constData(), "text/xml;charset=utf-8");
QCOMPARE(server.header("SoapAction").constData(), "\"http://www.kdab.com/xml/MyWsdl/getEmployeeCountry\"");
#if QT_VERSION >= 0x040800
QCOMPARE(server.header("Cookie").constData(), "biscuits=are good");
#elif QT_VERSION >= 0x040700
QCOMPARE(server.header("Cookie").constData(), "biscuits=\"are good\"");
#endif
QCOMPARE(ret.arguments().child(QLatin1String("employeeCountry")).value().toString(), QString::fromLatin1("France"));
}
client.setSoapVersion(KDSoapClientInterface::SOAP1_2);
{
KDSoapMessage ret = client.call(QLatin1String("getEmployeeCountry"), countryMessage());
// Check what we sent
QByteArray expectedRequestXml12 = expectedRequestXml;
expectedRequestXml12.replace("http://schemas.xmlsoap.org/soap/envelope/", "http://www.w3.org/2003/05/soap-envelope");
expectedRequestXml12.replace("http://schemas.xmlsoap.org/soap/encoding/", "http://www.w3.org/2003/05/soap-encoding");
QVERIFY(xmlBufferCompare(server.receivedData(), expectedRequestXml12));
QVERIFY(!ret.isFault());
QCOMPARE(server.header("Content-Type").constData(), "application/soap+xml;charset=utf-8;action=http://www.kdab.com/xml/MyWsdl/getEmployeeCountry");
QCOMPARE(ret.arguments().child(QLatin1String("employeeCountry")).value().toString(), QString::fromLatin1("France"));
#if QT_VERSION >= 0x040800
QCOMPARE(server.header("Cookie").constData(), "biscuits=are good");
#elif QT_VERSION >= 0x040700
QCOMPARE(server.header("Cookie").constData(), "biscuits=\"are good\"");
#endif
}
}
示例13: setCookies
void setCookies(Document* document, const KURL& url, const KURL& policyURL, const String& value)
{
QUrl u(url);
QUrl p(policyURL);
#if QT_VERSION >= 0x040400
QNetworkCookieJar* jar = cookieJar(document);
if (!jar)
return;
QList<QNetworkCookie> cookies = QNetworkCookie::parseCookies(QString(value).toAscii());
jar->setCookiesFromUrl(cookies, p);
#else
QCookieJar::cookieJar()->setCookies(u, p, (QString)value);
#endif
}
示例14: QObject
InfoExtractor::InfoExtractor(QObject *parent) :
QObject(parent), m_queue(), m_url(), m_replyTimer(new QTimer(this)),
m_accessManager(new QNetworkAccessManager(this)), m_reply(NULL)
{
//Définition du cookie pour avoir la page en anglais
QNetworkCookieJar *jar = new QNetworkCookieJar(this);
QNetworkCookie cookie("l", "en");
QList<QNetworkCookie> liste;
liste << cookie;
jar->setCookiesFromUrl(liste, MEGAUPLOAD);
m_accessManager->setCookieJar(jar);
m_replyTimer->setSingleShot(true);
m_replyTimer->setInterval(INFO_EXTRACTION_TIMEOUT);
connect(m_replyTimer, SIGNAL(timeout()), this, SLOT(replyTimeout()));
}
示例15: cookieRequestHeaderFieldValue
String cookieRequestHeaderFieldValue(const Document* document, const KURL &url)
{
QUrl u(url);
QNetworkCookieJar* jar = cookieJar(document);
if (!jar)
return String();
QList<QNetworkCookie> cookies = jar->cookiesForUrl(u);
if (cookies.isEmpty())
return String();
QStringList resultCookies;
foreach (QNetworkCookie networkCookie, cookies) {
resultCookies.append(QString::fromAscii(
networkCookie.toRawForm(QNetworkCookie::NameAndValueOnly).constData()));
}