本文整理汇总了C++中QNetworkReply::header方法的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkReply::header方法的具体用法?C++ QNetworkReply::header怎么用?C++ QNetworkReply::header使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QNetworkReply
的用法示例。
在下文中一共展示了QNetworkReply::header方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
void RequestModel::update()
{
QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
if (!reply)
return;
int offset;
for (offset = m_requests.count() - 1; offset >= 0; --offset) {
if (m_requests[offset].reply == reply)
break;
}
if (offset < 0)
return;
// Save reply headers
foreach (const QByteArray &header, reply->rawHeaderList() ) {
QPair<QByteArray, QByteArray> pair(header, reply->rawHeader(header));
m_requests[offset].replyHeaders.append(pair);
}
// Save reply info to be displayed
int status = reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt();
QString reason = reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();
m_requests[offset].response = QString(QLatin1String("%1 %2")).arg(status).arg(reason);
m_requests[offset].length = reply->header(QNetworkRequest::ContentLengthHeader).toInt();
m_requests[offset].contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString();
if (status == 302) {
QUrl target = reply->attribute( QNetworkRequest::RedirectionTargetAttribute ).toUrl();
m_requests[offset].info = tr("Redirect: %1").arg(target.toString());
}
}
示例2: onPublishFinished
void YandexNarodUploadJob::onPublishFinished()
{
QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
Q_ASSERT(reply);
reply->deleteLater();
QUrl url = reply->header(QNetworkRequest::LocationHeader).toUrl();
if (url.isRelative())
url = reply->url().resolved(url);
QString text = tr("File sent: %1 (%n bytes)\nDownload url: %2",
"%1 - filename, %2 - url",
m_data->size())
.arg(fileName(), url.toString());
Message message(text);
message.setIncoming(false);
message.setProperty("service", true);
if (ChatSession *s = ChatLayer::get(chatUnit(), false))
s->appendMessage(message);
message.setProperty("service", false);
chatUnit()->account()->getUnitForSession(chatUnit())->send(message);
setState(Finished);
}
示例3: errorDataReceived
void LocationManager::errorDataReceived(QNetworkReply& errorReply) {
if (errorReply.header(QNetworkRequest::ContentTypeHeader).toString().startsWith("application/json")) {
// we have some JSON error data we can parse for our error message
QJsonDocument responseJson = QJsonDocument::fromJson(errorReply.readAll());
QJsonObject dataObject = responseJson.object()["data"].toObject();
qDebug() << dataObject;
QString errorString = "There was a problem creating that location.\n";
// construct the error string from the returned attribute errors
foreach(const QString& key, dataObject.keys()) {
errorString += "\n\u2022 " + key + " - ";
QJsonValue keyedErrorValue = dataObject[key];
if (keyedErrorValue.isArray()) {
foreach(const QJsonValue& attributeErrorValue, keyedErrorValue.toArray()) {
errorString += attributeErrorValue.toString() + ", ";
}
// remove the trailing comma at end of error list
errorString.remove(errorString.length() - 2, 2);
} else if (keyedErrorValue.isString()) {
示例4: header
QVariant QNetworkReplyProto::header(QNetworkRequest::KnownHeaders header) const
{
QNetworkReply *item = qscriptvalue_cast<QNetworkReply*>(thisObject());
if (item)
return item->header(header);
return QVariant();
}
示例5: onQNetworkReplyReadyRead
void onQNetworkReplyReadyRead() {
DEBUG("onQNetworkReplyReadyRead()");
bool firstRead = invocationStatus != Invocation::RESPONSE_RECEIVED;
invocationStatus = Invocation::RESPONSE_RECEIVED;
QVariant statusCode = qreply->attribute( QNetworkRequest::HttpStatusCodeAttribute );
if (statusCode.isValid())
{
httpStatus = HTTPInvocationDefinition::resolveHttpStatus(statusCode.toInt());
} else {
// TODO: what to do, when no code?
invocationStatus = Invocation::ERROR;
result << InvocationErrors::INVOCATION_FAILED
<< Result::reasonFromDesc("Http status code not valid");
return;
}
if (httpStatus != HTTPInvocationDefinition::OK_200) {
invocationStatus = Invocation::ERROR;
result << InvocationErrors::INVOCATION_FAILED
<< Result::reasonFromDesc("Http error response code (not 200)")
<< Result::Meta("http_code", statusCode.toString());
// nothing to save to file
DEBUG("Error no data to save to file");
return;
}
// is target open?
if (!outputFile.isOpen()) {
if (!outputFile.open(QIODevice::WriteOnly)) {
q->abort();
result << InvocationErrors::INVOCATION_INVALID
<< Result::reasonFromDesc("Open output file failed")
<< Result::Meta("file_path", outputFilePath);
invocationStatus = Invocation::INVALID_INVOCATION;
emit q->finishedError(q);
return;
}
}
if (firstRead)
emit q->downloadStarted(q);
QVariant contentLength = qreply->header(QNetworkRequest::ContentLengthHeader);
qint64 bytesTotal = contentLength.isValid() ? contentLength.toInt() : -1;
int readBytes = 0;
while ( (readBytes = qreply->read(readBuffer, READ_BUFFER_SIZE) ) > 0) {
totalReadBytes += readBytes;
outputFile.write(readBuffer, readBytes);
onQNetworkReplyDownloadProgress(totalReadBytes, bytesTotal);
}
}
示例6: linkClickedFinished
void SidebarPrivate::linkClickedFinished()
{
QNetworkReply * reply = static_cast< QNetworkReply * >(sender());
QString target = reply->property("__target").toString();
QVariant redirectsVariant = reply->property("__redirects");
int redirects = redirectsVariant.isNull() ? 20 : redirectsVariant.toInt();
// Redirect?
QUrl redirectedUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
if (redirectedUrl.isValid())
{
if (redirectedUrl.isRelative())
{
QUrl oldUrl = reply->url();
redirectedUrl.setScheme(oldUrl.scheme());
redirectedUrl.setAuthority(oldUrl.authority());
}
if (redirects > 0)
{
QNetworkRequest request = reply->request();
request.setUrl(redirectedUrl);
QNetworkReply * reply = networkAccessManager()->get(request);
reply->setProperty("__target", target);
connect(reply, SIGNAL(finished()), this, SLOT(linkClickedFinished()));
}
else
{
// TOO MANY REDIRECTS
}
reply->deleteLater();
return;
}
// Check headers... if PDF then launch a new window, otherwise give it to the OS
QString contentType(reply->header(QNetworkRequest::ContentTypeHeader).toString());
if (contentType.contains("application/pdf")) {
emit urlRequested(reply->request().url(), "tab");
} else {
QUrl href(reply->request().url());
if (href.isValid()) {
if (href.scheme() == "http" || href.scheme() == "https") {
if (target == "sidebar") {
webView->setUrl(href);
slideLayout->push("web");
return;
}
}
QDesktopServices::openUrl(href);
}
// FIXME error
}
reply->deleteLater();
}
示例7: checkHeader
int Downloader::checkHeader(const QString &url)
{
qDebug() << "About to check";
QNetworkReply *reply = d->manager->head(d->createNetworkRequest(QUrl(url)));
reply->setProperty("is_Header_Check", true);
qDebug() << "Head check done";
QEventLoop e;
connect(reply, SIGNAL(finished()), &e, SLOT(quit()));
e.exec();
return reply->header(QNetworkRequest::LastModifiedHeader).toDateTime().toTime_t();
}
示例8: on_replyFinished
void CWizXmlRpcServer::on_replyFinished()
{
QNetworkReply* reply = qobject_cast<QNetworkReply *>(sender());
if (reply->error()) {
reply->deleteLater();
return;
}
QString strContentType = reply->header(QNetworkRequest::ContentTypeHeader).toString();
if (strContentType != "text/xml;charset=UTF-8") {
processError(errorContentType, 0, "Invalid content type of response");
reply->deleteLater();
return;
}
m_replyData = reply->readAll();
#ifdef WIZNOTE_DEBUG_XMLRPC
QString requestFile = QDir::tempPath() + "/WizNote/" + m_strMethodName;
QString replyFile = QDir::tempPath() + "/WizNote/on_" + m_strMethodName;
WizSaveUnicodeTextToUtf8File(requestFile, QString(m_requestData));
WizSaveUnicodeTextToUtf8File(replyFile, QString(m_replyData));
#endif
QString strXml = QString::fromUtf8(m_replyData.constData());
CWizXMLDocument doc;
if (!doc.LoadXML(strXml)) {
processError(errorXmlFormat, 0, "Invalid xml");
reply->deleteLater();
return;
}
CWizXmlRpcValue* pRet = NULL;
if (!WizXmlRpcResultFromXml(doc, &pRet)) {
processError(errorXmlRpcFormat, 0, "Can not parse xmlrpc");
reply->deleteLater();
return;
}
Q_ASSERT(pRet);
if (CWizXmlRpcFaultValue* pFault = dynamic_cast<CWizXmlRpcFaultValue *>(pRet)) {
processError(errorXmlRpcFault, pFault->GetFaultCode(), pFault->GetFaultString());
reply->deleteLater();
delete pRet;
return;
}
processReturn(*pRet);
}
示例9: trackedGETReadyRead
void KVNetworkAccessManager::trackedGETReadyRead()
{
QNetworkReply *reply = qobject_cast<QNetworkReply*>(QObject::sender());
bool ok;
/*qint64 length = */reply->header(QNetworkRequest::ContentLengthHeader).toLongLong(&ok);
// Don't report progress for replies without a Content-Length
if(ok)
{
trackedGETProgress += reply->bytesAvailable();
emit trackedProgressChanged(trackedGETProgress, trackedGETTotalSize);
}
}
示例10: handleMetadata
void Plugin::handleMetadata ()
{
QNetworkReply *reply = qobject_cast<QNetworkReply*> (sender ());
if (!reply)
{
qWarning () << Q_FUNC_INFO
<< "sender is not a QNetworkReply:"
<< sender ();
return;
}
const QString& pasteUrl = reply->header (QNetworkRequest::LocationHeader).toString ();
QPointer<QObject> entryObj = Reply2Entry_ [reply];
if (!entryObj)
{
QApplication::clipboard ()->setText (pasteUrl, QClipboard::Clipboard);
QApplication::clipboard ()->setText (pasteUrl, QClipboard::Selection);
const Entity& e = Util::MakeNotification (tr ("Text pasted"),
tr ("Your text has been pasted: %1. The URL has "
"been copied to the clipboard."),
PInfo_);
emit gotEntity (e);
return;
}
ICLEntry *entry = qobject_cast<ICLEntry*> (entryObj);
if (!entry)
{
qWarning () << Q_FUNC_INFO
<< "unable to cast"
<< entryObj
<< "to ICLEntry";
return;
}
IMessage::MessageType type =
entry->GetEntryType () == ICLEntry::ETMUC ?
IMessage::MTMUCMessage :
IMessage::MTChatMessage;
QObject *msgObj = entry->CreateMessage (type, QString (), pasteUrl);
IMessage *msg = qobject_cast<IMessage*> (msgObj);
if (!msg)
{
qWarning () << Q_FUNC_INFO
<< "unable to cast"
<< msgObj
<< "to IMessage";
return;
}
msg->Send ();
}
示例11: getRealUrl
QString DownloadWidget::getRealUrl(QString url)
{
QString realUrl;
if(url.contains("plyz"))
{
int tryTimes=5;
//尝试tryTimes次
QString realUrl_temp = this->url;
while(tryTimes --)
{
QEventLoop loop;
QNetworkReply *reply = manager->head(QNetworkRequest(realUrl_temp));
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
QVariant varLocation = reply->header(QNetworkRequest::LocationHeader);
if(!varLocation.isNull())
{
realUrl_temp = varLocation.toString();
//qDebug()<<realUrl_temp;
continue;
}
delete reply;
break;
}
realUrl = realUrl_temp;
if(realUrl == "")
{
myTipWin.show();
myTipWin.setText("获取下载链接失败。");
myTipWin.timeToHide(3);
}
}else if(url.contains("baidupcs.com"))
{
realUrl= url;
}else
{
QNetworkRequest request0;
request0.setUrl(QString("http://www.mvgather.com/mvgather/api/getRealUrl.php?url=%0").arg(url));//
QNetworkReply *reply0 = manager->get(request0);
QEventLoop loop0;
QObject::connect(reply0, SIGNAL(finished()), &loop0, SLOT(quit()));
loop0.exec();
QByteArray data0 = reply0->readAll();
realUrl = data0;
}
//qDebug()<<realUrl;
return realUrl;
}
示例12: onProgress
void WebLoadManager::onProgress(qint64 already, qint64 size) {
QNetworkReply *reply = qobject_cast<QNetworkReply*>(QObject::sender());
if (!reply) return;
Replies::iterator j = _replies.find(reply);
if (j == _replies.cend()) { // handled already
return;
}
webFileLoaderPrivate *loader = j.value();
WebReplyProcessResult result = WebReplyProcessProgress;
QVariant statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
int32 status = statusCode.isValid() ? statusCode.toInt() : 200;
if (status != 200 && status != 206 && status != 416) {
if (status == 301 || status == 302) {
QString loc = reply->header(QNetworkRequest::LocationHeader).toString();
if (!loc.isEmpty()) {
if (loader->oneMoreRedirect()) {
sendRequest(loader, loc);
return;
} else {
LOG(("Network Error: Too many HTTP redirects in onFinished() for web file loader: %1").arg(loc));
result = WebReplyProcessError;
}
}
} else {
LOG(("Network Error: Bad HTTP status received in WebLoadManager::onProgress(): %1").arg(statusCode.toInt()));
result = WebReplyProcessError;
}
} else {
loader->setProgress(already, size);
QByteArray r = reply->readAll();
if (!r.isEmpty()) {
loader->addData(r);
}
if (size == 0) {
LOG(("Network Error: Zero size received for HTTP download progress in WebLoadManager::onProgress(): %1 / %2").arg(already).arg(size));
result = WebReplyProcessError;
}
}
if (!handleReplyResult(loader, result)) {
_replies.erase(j);
_loaders.remove(loader);
delete loader;
reply->abort();
reply->deleteLater();
}
}
示例13: handleMetadata
void PasteServiceBase::handleMetadata ()
{
QNetworkReply *reply = qobject_cast<QNetworkReply*> (sender ());
if (!reply)
{
qWarning () << Q_FUNC_INFO
<< "sender is not a QNetworkReply:"
<< sender ();
return;
}
const auto& location = reply->header (QNetworkRequest::LocationHeader).toString ();
if (!location.isEmpty ())
FeedURL (location);
}
示例14: GetFileSize
//用阻塞的方式获取下载文件的长度
qint64 TcDownloadList::GetFileSize(QUrl url)
{
QNetworkAccessManager manager;
//qDebug() << "Getting the file size...";
QEventLoop loop;
//发出请求,获取目标地址的头部信息
QNetworkReply *reply = manager.head(QNetworkRequest(url));
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()), Qt::DirectConnection);
loop.exec();
QVariant var = reply->header(QNetworkRequest::ContentLengthHeader);
reply->deleteLater();
qint64 size = var.toLongLong();
//qDebug() << "The file size is: " << size;
return size;
}
示例15: onWebPageDownloaded
void Uploadtous::onWebPageDownloaded() {
QNetworkReply *reply = qobject_cast<QNetworkReply*>(this->sender());
if (!reply) {
emit error(NetworkError);
return;
}
QRegExp re("http://storage\\d+.(uploadto.us|ultramegabit.com)/[^'\"]+");
QString redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString();
if (redirect.isEmpty()) {
redirect = reply->header(QNetworkRequest::LocationHeader).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 {
m_captchaKey = response.section("www.google.com/recaptcha/api/challenge?k=", 1, 1).section('"', 0, 0);
m_fileId = response.section("encode\" value=\"", 1, 1).section('"', 0, 0);
m_token = response.section("csrf_token\" value=\"", 1, 1).section('"', 0, 0);
if ((m_captchaKey.isEmpty()) || (m_fileId.isEmpty()) || (m_token.isEmpty())) {
emit error(UnknownError);
}
else {
this->startWait(30000);
this->connect(this, SIGNAL(waitFinished()), this, SLOT(downloadCaptcha()));
}
}
}
reply->deleteLater();
}