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


C++ QNetworkAccessManager::deleteResource方法代码示例

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


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

示例1: executeQuery

// 执行请求的辅助函数
void HttpClientPrivate::executeQuery(HttpClientPrivate *d, HttpMethod method,
                                     std::function<void (const QString &)> successHandler,
                                     std::function<void (const QString &)> errorHandler,
                                     const char *encoding) {
    // 如果不使用外部的 manager 则创建一个新的,在访问完成后会自动删除掉
    bool debug = d->debug;
    bool internal;
    QNetworkAccessManager *manager = HttpClientPrivate::getManager(d, &internal);
    QNetworkRequest        request = HttpClientPrivate::createRequest(d, method);
    QNetworkReply           *reply = nullptr;

    switch (method) {
    case HttpClientPrivate::GET:
        reply = manager->get(request);
        break;
    case HttpClientPrivate::POST:
        reply = manager->post(request, d->useJson ? d->json.toUtf8() : d->params.toString(QUrl::FullyEncoded).toUtf8());
        break;
    case HttpClientPrivate::PUT:
        reply = manager->put(request, d->useJson ? d->json.toUtf8() : d->params.toString(QUrl::FullyEncoded).toUtf8());
        break;
    case HttpClientPrivate::DELETE:
        reply = manager->deleteResource(request);
        break;
    default:
        break;
    }

    QObject::connect(reply, &QNetworkReply::finished, [=] {
        QString successMessage = HttpClientPrivate::readReply(reply, encoding); // 请求结束时一次性读取所有响应数据
        QString errorMessage   = reply->errorString();
        HttpClientPrivate::handleFinish(debug, successMessage, errorMessage, successHandler, errorHandler,
                                        reply, internal ? manager : nullptr);
    });
}
开发者ID:xtuer,项目名称:Qt,代码行数:36,代码来源:HttpClient.cpp

示例2: exec

QJsonObject SeleniumServerHub::exec(QString url, QByteArray rawBody, int method)
{
    m_result = "";
    QJsonObject result;

    QUrl urlObject(m_urlHub + url);
    QNetworkRequest request(urlObject);

    QString contentType = "application/json";

    QNetworkAccessManager* manager = new QNetworkAccessManager(this);

    if(method == GET) {

        m_reply = manager->get(request);

    } else if(method == POST) {

        if(rawBody.isEmpty()) {

            request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
            m_reply = manager->post(request, "");

        } else {

            QByteArray postDataSize = QByteArray::number(rawBody.size());
            request.setRawHeader("Content-Type", contentType.toLatin1());
            request.setRawHeader("Content-Length", postDataSize);

            m_reply = manager->post(request, rawBody);
        }

    } else if(method == DELETE) {

        m_reply = manager->deleteResource(request);

    } else {
        throw (new QueleniumException("Unsupported method", 99));
    }

    connect(m_reply, SIGNAL(readyRead()), SLOT(slotReplyResponse()));
    connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(slotReplyError()));
    connect(m_reply, SIGNAL(finished()), SLOT(slotFinishRequest()));

    //this loop for synchronize requests
    QEventLoop loop;
    connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), &loop, SLOT(quit()));
    connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), &loop, SLOT(deleteLater()));
    connect(m_reply, SIGNAL(finished()), &loop, SLOT(quit()));
    loop.exec();

    if(m_result.trimmed().isEmpty()) {
        WebDriverException::throwException("Empty reply from server");
    }

    result = QJsonDocument::fromJson(m_result.toUtf8()).object();

    if(result["status"].toInt() != ResponseStatusCodes::SUCCESS) {

        QString message = result["state"].toString();
        if(result["value"].isObject() && result["value"].toObject()["message"].isString()) {
            message = result["value"].toObject()["message"].toString();
        }

        WebDriverException::throwException(message, result["status"].toInt());
    }

    return result;
}
开发者ID:stoic1979,项目名称:quelenium,代码行数:69,代码来源:seleniumserverhub.cpp


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