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


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

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


在下文中一共展示了QNetworkAccessManager::put方法的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: put

void HttpInterface::put(QUrl url, QByteArray data, HttpInterface *interface)
{
    QNetworkAccessManager *manager = new QNetworkAccessManager(this);
    QByteArray *buffer = new QByteArray();
    buffer->clear();
    QNetworkRequest request;
    request.setHeader(QNetworkRequest::ContentTypeHeader, QString("text/xml"));
    request.setUrl(url);
    QNetworkReply *reply = manager->put(request,data);
    connect(reply,&QNetworkReply::readyRead,[=](){buffer->append(reply->readAll());});
    connect(reply,&QNetworkReply::finished,[=](){finished(*buffer, interface);});
}
开发者ID:maruncz,项目名称:PentaxRemote,代码行数:12,代码来源:httpinterface.cpp


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