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


C++ QNetworkReply::attribute方法代码示例

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


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

示例1: shutdownServer

// Shutdown the application server
bool shutdownServer(QUrl url)
{
    QNetworkAccessManager manager;
    QEventLoop loop;
    QNetworkReply *reply;
    QVariant redirectUrl;

    url.setPath("/misc/shutdown");

    do
    {
        reply = manager.get(QNetworkRequest(url));

        QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
        loop.exec();

        redirectUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
        url = redirectUrl.toUrl();

        if (!redirectUrl.isNull())
            delete reply;

    } while (!redirectUrl.isNull());

    if (reply->error() != QNetworkReply::NoError)
    {
        return false;
    }

    QString response = reply->readAll();

    if (response != "SHUTDOWN")
    {
        qDebug() << "Failed to connect, server response: " << response;
        return false;
    }

    return true;
}
开发者ID:thaJeztah,项目名称:pgadmin4,代码行数:40,代码来源:pgAdmin4.cpp

示例2: checkUrlIsValid

void Uploadtous::checkUrlIsValid() {
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(this->sender());

    if (!reply) {
        emit urlChecked(false);
        return;
    }

    QString redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString();
    QRegExp re("http://storage\\d+.(uploadto.us|ultramegabit.com)/[^'\"]+");

    if ((!redirect.isEmpty()) && (re.indexIn(redirect) == -1)) {
        this->checkUrl(QUrl(redirect));
    }
    else {
        QString response(reply->readAll());
        QString fileName = response.section("<title>uploadto.us -", 1, 1).section('<', 0, 0).trimmed();        
        emit urlChecked(true, reply->request().url(), this->serviceName(), fileName);
    }

    reply->deleteLater();
}
开发者ID:marxoft,项目名称:qdl,代码行数:22,代码来源:uploadtous.cpp

示例3: checkUrlIsValid

void FileDefend::checkUrlIsValid() {
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(this->sender());

    if (!reply) {
        emit urlChecked(false);
        return;
    }

    QString redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString();
    QRegExp re("http://\\w+.filedefend.com:\\d+/d/[^'\"]+");

    if ((!redirect.isEmpty()) && (re.indexIn(redirect) == -1)) {
        this->checkUrl(QUrl(redirect));
    }
    else {
        QString response(reply->readAll());
        QString fileName = response.section("fname\" value=\"", 1, 1).section('"', 0, 0);

        if (fileName.isEmpty()) {
            emit urlChecked(false);
        }
        else {
            QString urlString = reply->request().url().toString();

            if (!urlString.endsWith(fileName)) {
                if (!urlString.endsWith('/')) {
                    urlString.append('/');
                }

                urlString.append(fileName);
            }

            QUrl url(urlString);
            emit urlChecked(true, url, this->serviceName(), fileName);
        }
    }

    reply->deleteLater();
}
开发者ID:marxoft,项目名称:qdl,代码行数:39,代码来源:filedefend.cpp

示例4: onCaptchaDownloaded

void SolveMediaRecaptchaPlugin::onCaptchaDownloaded() {
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());

    if (!reply) {
        emit error(tr("Network error"));
        return;
    }

    switch (reply->error()) {
    case QNetworkReply::NoError:
        break;
    case QNetworkReply::OperationCanceledError:
        reply->deleteLater();
        return;
    default:
        emit error(reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString());
        reply->deleteLater();
        return;
    }

    const QVariantMap map = QtJson::Json::parse(QString::fromUtf8(reply->readAll())).toMap();
    reply->deleteLater();

    if (map.contains("ACChallengeResult")) {
        const QVariantMap result = map.value("ACChallengeResult").toMap();

        if (result.contains("chid")) {
            const QString challenge = result.value("chid").toString();

            if (!challenge.isEmpty()) {
                downloadCaptchaImage(challenge);
                return;
            }
        }
    }

    emit error(tr("No captcha challenge found"));
}
开发者ID:wulinfa,项目名称:qdl2,代码行数:38,代码来源:solvemediarecaptchaplugin.cpp

示例5: loginResult

void Session::Request::onLoginPageResult() {
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(QObject::sender());
    int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
    if (status != 302) {
        emit loginResult(0x01, "Failed to log in (invalid password or expired session ID).");
    }
    else {
        QList<QNetworkCookie> cookies = reply->manager()->cookieJar()->cookiesForUrl(MainUrl());
        for (auto &cookie : cookies) {
            if (QString(cookie.name()) == SessionIdCookie()) {
                _sessionId = cookie.value();
                emit loginResult(0x00, "Logged in!");
                break;
            }
        }

        QNetworkRequest request = createRequest(AccountUrl());
        QNetworkReply *r = _manager->get(request);

        connect(r, &QNetworkReply::finished, this, &Session::Request::Request::onAccountPageResult);
    }
    reply->deleteLater();
}
开发者ID:Novynn,项目名称:Adamant,代码行数:23,代码来源:sessionrequest.cpp

示例6: getByUrl

/**
 * @brief 通过HTTP GET发送URL,因为QNetWorkAccessManager默认不CACHE,所以不必设置
 **/
QByteArray WebUtils::getByUrl(const QUrl &url)
{
  QNetworkReply *reply = qnam.get(QNetworkRequest(url));
  QEventLoop loop;
  connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
  loop.exec();

  QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);

  // WARNING: taobao only have once redirect url
  if (reply->error()) {
    qDebug() << reply->errorString();
    return "";
  } else if (!redirectionTarget.isNull()) {
    QUrl newUrl = url.resolved(redirectionTarget.toUrl());
    reply->deleteLater();
    return getByUrl(newUrl);
  }

  QByteArray returnStr = reply->readAll();
  reply->deleteLater();
  return returnStr;
}
开发者ID:jdwx-new,项目名称:TaobaoCppQtSDK,代码行数:26,代码来源:WebUtils.cpp

示例7: onCaptchaImageDownloaded

void SolveMediaRecaptchaPlugin::onCaptchaImageDownloaded() {
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());

    if (!reply) {
        emit error(tr("Network error"));
        return;
    }

    switch (reply->error()) {
    case QNetworkReply::NoError:
        break;
    case QNetworkReply::OperationCanceledError:
        reply->deleteLater();
        return;
    default:
        emit error(reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString());
        reply->deleteLater();
        return;
    }

    emit captcha(CaptchaType::Image, QByteArray(m_challenge.toUtf8() + "\n" + reply->readAll().toBase64()));
    reply->deleteLater();
}
开发者ID:marxoft,项目名称:qdl2,代码行数:23,代码来源:solvemediarecaptchaplugin.cpp

示例8: checkUrlIsValid

void DepositFiles::checkUrlIsValid() {
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(this->sender());

    if (!reply) {
        emit urlChecked(false);
        return;
    }

    QString redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString();
    QRegExp re("http(s|)://fileshare\\d+.(depositfiles.com|dfiles.\\w+)/[^'\"]+");

    if ((!redirect.isEmpty()) && (re.indexIn(redirect) == -1)) {
        this->checkUrl(QUrl(redirect));
    }
    else {
        QString response(reply->readAll());

        if (response.contains("file does not exist")) {
            emit urlChecked(false);
        }
        else {
            QScriptEngine engine;
            QString script = response.section("eval( ", 1, 1).section(");", 0, 0);
            QString fileNameElement = engine.evaluate(script).toString();

            if (fileNameElement.isEmpty()) {
                emit urlChecked(false);
            }
            else {
                QString fileName = fileNameElement.section("title=\"", 1, 1).section('"', 0, 0);
                emit urlChecked(true, reply->request().url(), this->serviceName(), fileName);
            }
        }
    }

    reply->deleteLater();
}
开发者ID:marxoft,项目名称:qdl,代码行数:37,代码来源:depositfiles.cpp

示例9: on_queryUserAvatar_finished

void AvatarDownloader::on_queryUserAvatar_finished()
{
    QNetworkReply* reply = qobject_cast<QNetworkReply *>(sender());
    reply->deleteLater();

    if (reply->error()) {
        qDebug() << "[AvatarHost]Error occured: " << reply->errorString();
        fetchUserAvatarEnd(false);
        return;
    }

    // cause we use "default", redirection may occur
    QVariant possibleRedirectUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
    m_urlRedirectedTo = redirectUrl(possibleRedirectUrl.toUrl(), m_urlRedirectedTo);

    if(!m_urlRedirectedTo.isEmpty()) {
        qDebug() << "[AvatarHost]fetching redirected, url: "
                 << m_urlRedirectedTo.toString();

        QNetworkReply* replyNext = m_net->get(QNetworkRequest(m_urlRedirectedTo));
        connect(replyNext, SIGNAL(finished()), SLOT(on_queryUserAvatar_finished()));
    } else {
        // finally arrive destination...

        // read and save avatar
        QByteArray bReply = reply->readAll();

        if (!save(m_strCurrentUser, bReply)) {
            qDebug() << "[AvatarHost]failed: unable to save user avatar, guid: " << m_strCurrentUser;
            fetchUserAvatarEnd(false);
            return;
        }

        qDebug() << "[AvatarHost]fetching finished, guid: " << m_strCurrentUser;
        fetchUserAvatarEnd(true);
    }
}
开发者ID:boris-callthepolice,项目名称:WizQTClient,代码行数:37,代码来源:avatar.cpp

示例10: handleFormatCheckFinished

	void YoutubePlayer::handleFormatCheckFinished ()
	{
		Ui_.Quality_->setEnabled (true);
		QNetworkReply *rep = qobject_cast<QNetworkReply*> (sender ());
		if (!rep)
		{
			qWarning () << Q_FUNC_INFO
				<< "sender is not a QNetworkReply*"
				<< sender ();
			return;
		}
		rep->deleteLater ();

		QString fmt = rep->property ("fmt").toString ();

		int code = rep->attribute (QNetworkRequest::HttpStatusCodeAttribute).toInt ();
		if (code == 404)
		{
			QMessageBox::critical (this,
					"LeechCraft",
					tr ("This format is unavailable, please select another one."));
			return;
		}
		// 3xx codes => redirection
		else if (code / 100 == 3)
		{
			QUrl url = rep->header (QNetworkRequest::LocationHeader).value<QUrl> ();
			ReqAndContinueFormatCheck (url)->setProperty ("fmt", fmt);
			return;
		}
		XmlSettingsManager::Instance ()->
			setProperty ("YoutubePreviousQuality", fmt);

		QUrl url = OriginalURL_;
		url.addQueryItem ("fmt", fmt);
		SetVideoUrl (url);
	}
开发者ID:Zereal,项目名称:leechcraft,代码行数:37,代码来源:youtubeplayer.cpp

示例11: onWebPageDownloaded

void Cramit::onWebPageDownloaded() {
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(this->sender());

    if (!reply) {
        emit error(NetworkError);
        return;
    }

    QRegExp re("http://cramit.in/file_download/[^'\"]+");
    QString redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString();

    if (re.indexIn(redirect) == 0) {
        QNetworkRequest request;
        request.setUrl(QUrl(re.cap()));
        emit downloadRequestReady(request);
    }
    else if (!redirect.isEmpty()) {
        this->getDownloadRequest(QUrl(redirect));
    }
    else {
        QString response(reply->readAll());

        if (re.indexIn(response) >= 0) {
            QNetworkRequest request;
            request.setUrl(QUrl(re.cap()));
            emit downloadRequestReady(request);
        }
        else if (response.contains("File Not Found")) {
            emit error(NotFound);
        }
        else {
            this->getWaitTime();
        }
    }

    reply->deleteLater();
}
开发者ID:marxoft,项目名称:qdl,代码行数:37,代码来源:cramit.cpp

示例12: onLoginFinished

void Pastebin::onLoginFinished() {
    QNetworkReply *networkReply = qobject_cast<QNetworkReply *>(sender());
    QVariant statusCode = networkReply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    qDebug() << "Login complete:" << statusCode.toInt();

    if(networkReply->error() == QNetworkReply::NoError) {
        QString response = networkReply->readAll();

        qDebug() << "Response:" << response;

        if(response.startsWith("Bad API request")) {
            emit loginFailed(response);
        }
        else {
            QNetworkRequest networkRequest = networkReply->request();

            emit loginComplete(response);
        }
    }
    else {
        qWarning() << "Error:" << networkReply->errorString();
        emit loginFailed(QString::null);
    }
}
开发者ID:dkonigsberg,项目名称:LogicPaste,代码行数:24,代码来源:Pastebin.cpp

示例13: checkReply

void SearchController::checkReply() {
	QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());

	QString response;
	if (reply) {
		if (reply->error() == QNetworkReply::NoError) {
			const int available = reply->bytesAvailable();
			if (available > 0) {
				const QByteArray buffer(reply->readAll());
				response = QString::fromUtf8(buffer);
				QRegExp loading("Votre recherche est en cours, merci de bien vouloir patienter");
				if(loading.indexIn(response, 0) != -1)
					waitMore(response);
				else
					parse(response);
			}
		} else {
			response = tr("Error: %1 status: %2").arg(reply->errorString(), reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString());
			qDebug() << response;
		}

		reply->deleteLater();
	}
}
开发者ID:Jendorski,项目名称:HFRBlack,代码行数:24,代码来源:SearchController.cpp

示例14: onSubmitPasteFinished

void Pastebin::onSubmitPasteFinished() {
    QNetworkReply *networkReply = qobject_cast<QNetworkReply *>(sender());
    QVariant statusCode = networkReply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    qDebug() << "Paste complete:" << statusCode.toInt();

    if(networkReply->error() == QNetworkReply::NoError) {
        const QString response = networkReply->readAll();

        qDebug() << "Response:" << response;

        if(response.startsWith("Bad API request")) {
            qWarning() << "Error with paste";
            emit pasteFailed(response);
        }
        else {
            qDebug() << "Paste successful";
            emit pasteComplete(response);
        }
    }
    else {
        qWarning() << "Error with paste:" << networkReply->errorString();
        emit pasteFailed(QString::null);
    }
}
开发者ID:dkonigsberg,项目名称:LogicPaste,代码行数:24,代码来源:Pastebin.cpp

示例15: doGet

requestStruct HTTPdownloader::doGet(QString url) {
	int tries = 0;
	requestStruct strct;
	do {
		qDebug() << "get" << url;
		QNetworkRequest req;
		req.setUrl(QUrl(url));
		//req.setRawHeader("User-Agent", "bsToGetLinklist/1.0 (Nokia; Qt)"); //was a test because bs.to wasnt returning valid results
		QNetworkReply *reply = this->get(static_cast<const QNetworkRequest>(req));
		QEventLoop loop;
		connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
		loop.exec();

		strct.httpStatusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
		strct.data = reply->readAll();
		strct.url = url;
		qDebug() << "getDone" << strct.httpStatusCode << strct.data.size() << url << tries;
		reply->deleteLater();
		if (strct.httpStatusCode == 200)
			return strct;
		++tries;
	} while (tries < 4);
	return strct;
}
开发者ID:dedmen,项目名称:bsToGetLinklist,代码行数:24,代码来源:httpdownloader.cpp


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