本文整理汇总了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);
});
}
示例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);});
}