本文整理汇总了C++中QNetworkCookieJar::cookiesForUrl方法的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkCookieJar::cookiesForUrl方法的具体用法?C++ QNetworkCookieJar::cookiesForUrl怎么用?C++ QNetworkCookieJar::cookiesForUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QNetworkCookieJar
的用法示例。
在下文中一共展示了QNetworkCookieJar::cookiesForUrl方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
}
示例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: 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("; "));
}
示例4: finished_loading
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();
}
示例5: finished
void YafOAuth::finished(QNetworkReply *reply)
{
int attr = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
if(attr == 302) // redirect
{
m_oAuthTimer->stop();
QString url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString();
if(url.contains("http://passport-ckicheck.yandex.ru/passport?mode=ckicheck")
|| url.contains("https://oauth.yandex.ru/authorize?allow=True&request_id"))
{
m_view->load(reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl());
if (!m_oAuthTimer->isActive())
m_oAuthTimer->start(10*1000);
}
else 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();
login = login.replace(".", "-");
break;
}
}
delete m_view;
m_view = NULL;
emit authFinished(eNO_ERROR, login, m_token);
}
else if(url.contains("error=access_denied"))
{
delete m_view;
m_view = NULL;
emit authFinished(eERROR_CANCEL, "", "");
}
}
}
示例6: cookieRequestHeaderFieldValue
String cookieRequestHeaderFieldValue(const NetworkStorageSession& session, const KURL& /*firstParty*/, const KURL& url)
{
QNetworkCookieJar* jar = session.context() ? session.context()->networkAccessManager()->cookieJar() : SharedCookieJarQt::shared();
if (!jar)
return String();
QList<QNetworkCookie> cookies = jar->cookiesForUrl(QUrl(url));
if (cookies.isEmpty())
return String();
QStringList resultCookies;
foreach (QNetworkCookie networkCookie, cookies)
resultCookies.append(QString::fromLatin1(networkCookie.toRawForm(QNetworkCookie::NameAndValueOnly).constData()));
return resultCookies.join(QLatin1String("; "));
}
示例7: 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()));
}
示例8: cookieRequestHeaderFieldValue
String cookieRequestHeaderFieldValue(const Document* document, const KURL &url)
{
NetworkingContext* context = networkingContext(document);
if (!context)
return String();
QNetworkCookieJar* jar = context->networkAccessManager()->cookieJar();
QList<QNetworkCookie> cookies = jar->cookiesForUrl(QUrl(url));
if (cookies.isEmpty())
return String();
QStringList resultCookies;
foreach (QNetworkCookie networkCookie, cookies)
resultCookies.append(QString::fromLatin1(networkCookie.toRawForm(QNetworkCookie::NameAndValueOnly).constData()));
return resultCookies.join(QLatin1String("; "));
}
示例9: cookies
String cookies(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) {
if (networkCookie.isHttpOnly())
continue;
resultCookies.append(QString::fromAscii(
networkCookie.toRawForm(QNetworkCookie::NameAndValueOnly).constData()));
}
return resultCookies.join(QLatin1String("; "));
}
示例10: cookiesForDOM
String cookiesForDOM(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url)
{
QNetworkCookieJar* jar = session.context() ? session.context()->networkAccessManager()->cookieJar() : SharedCookieJarQt::shared();
if (!jar)
return String();
QUrl urlForCookies(url);
QUrl firstPartyUrl(firstParty);
if (!thirdPartyCookiePolicyPermits(session.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("; "));
}
示例11: load
void MediaPlayerPrivate::load(const String& url)
{
// We are now loading
if (m_networkState != MediaPlayer::Loading) {
m_networkState = MediaPlayer::Loading;
m_player->networkStateChanged();
}
// And we don't have any data yet
if (m_readyState != MediaPlayer::HaveNothing) {
m_readyState = MediaPlayer::HaveNothing;
m_player->readyStateChanged();
}
const QUrl rUrl = QUrl(QString(url));
const QString scheme = rUrl.scheme().toLower();
// Grab the client media element
HTMLMediaElement* element = static_cast<HTMLMediaElement*>(m_player->mediaPlayerClient());
// Construct the media content with a network request if the resource is http[s]
if (scheme == "http" || scheme == "https") {
QNetworkRequest request = QNetworkRequest(rUrl);
// Grab the current document
Document* document = element->document();
if (!document)
document = element->ownerDocument();
// Grab the frame and network manager
Frame* frame = document ? document->frame() : 0;
FrameLoaderClientQt* frameLoader = frame ? static_cast<FrameLoaderClientQt*>(frame->loader()->client()) : 0;
QNetworkAccessManager* manager = frameLoader ? frameLoader->webFrame()->page()->networkAccessManager() : 0;
if (document && manager) {
// Set the cookies
QNetworkCookieJar* jar = manager->cookieJar();
QList<QNetworkCookie> cookies = jar->cookiesForUrl(rUrl);
// Don't set the header if there are no cookies.
// This prevents a warning from being emitted.
if (!cookies.isEmpty())
request.setHeader(QNetworkRequest::CookieHeader, qVariantFromValue(cookies));
// Set the refferer, but not when requesting insecure content from a secure page
QUrl documentUrl = QUrl(QString(document->documentURI()));
if (documentUrl.scheme().toLower() == "http" || scheme == "https")
request.setRawHeader("Referer", documentUrl.toEncoded());
// Set the user agent
request.setRawHeader("User-Agent", frameLoader->userAgent(rUrl).utf8().data());
}
m_mediaPlayer->setMedia(QMediaContent(request));
} else {
// Otherwise, just use the URL
m_mediaPlayer->setMedia(QMediaContent(rUrl));
}
// Set the current volume and mute status
// We get these from the element, rather than the player, in case we have
// transitioned from a media engine which doesn't support muting, to a media
// engine which does.
m_mediaPlayer->setMuted(element->muted());
m_mediaPlayer->setVolume(static_cast<int>(element->volume() * 100.0));
}
示例12: commitLoad
void MediaPlayerPrivateQt::commitLoad(const String& url)
{
// We are now loading
if (m_networkState != MediaPlayer::Loading) {
m_networkState = MediaPlayer::Loading;
m_webCorePlayer->networkStateChanged();
}
// And we don't have any data yet
if (m_readyState != MediaPlayer::HaveNothing) {
m_readyState = MediaPlayer::HaveNothing;
m_webCorePlayer->readyStateChanged();
}
KURL kUrl(ParsedURLString, url);
const QUrl rUrl = kUrl;
const QString scheme = rUrl.scheme().toLower();
// Grab the client media element
HTMLMediaElement* element = static_cast<HTMLMediaElement*>(m_webCorePlayer->mediaPlayerClient());
// Construct the media content with a network request if the resource is http[s]
if (scheme == QString::fromLatin1("http") || scheme == QString::fromLatin1("https")) {
QNetworkRequest request = QNetworkRequest(rUrl);
// Grab the current document
Document* document = element->document();
if (!document)
document = element->ownerDocument();
// Grab the frame and network manager
Frame* frame = document ? document->frame() : 0;
FrameLoader* frameLoader = frame ? frame->loader() : 0;
QNetworkAccessManager* manager = frameLoader ? frameLoader->networkingContext()->networkAccessManager() : 0;
if (manager) {
// Set the cookies
QNetworkCookieJar* jar = manager->cookieJar();
QList<QNetworkCookie> cookies = jar->cookiesForUrl(rUrl);
// Don't set the header if there are no cookies.
// This prevents a warning from being emitted.
if (!cookies.isEmpty())
request.setHeader(QNetworkRequest::CookieHeader, QVariant::fromValue(cookies));
// Set the refferer, but not when requesting insecure content from a secure page
QUrl documentUrl = QUrl(QString(document->documentURI()));
if (documentUrl.scheme().toLower() == QString::fromLatin1("http") || scheme == QString::fromLatin1("https"))
request.setRawHeader("Referer", documentUrl.toEncoded());
// Set the user agent
request.setRawHeader("User-Agent", frameLoader->userAgent(rUrl).utf8().data());
}
m_mediaPlayer->setMedia(QMediaContent(request));
} else {
// Otherwise, just use the URL
m_mediaPlayer->setMedia(QMediaContent(rUrl));
}
// Set the current volume and mute status
// We get these from the element, rather than the player, in case we have
// transitioned from a media engine which doesn't support muting, to a media
// engine which does.
m_mediaPlayer->setMuted(element->muted());
m_mediaPlayer->setVolume(static_cast<int>(element->volume() * 100.0));
// Don't send PlaybackChanged notification for pre-roll.
m_suppressNextPlaybackChanged = true;
// Setting a media source will start loading the media, but we need
// to pre-roll as well to get video size-hints and buffer-status
if (element->paused())
m_mediaPlayer->pause();
else
m_mediaPlayer->play();
}