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


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

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


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

示例1: queryWeather

/*Name: queryWeather
 *Description: Function used to query OpenWeatherMap.com to retrieve WeatherModel
 *Parameter Description: Integer representing current town selected from list
 */
void WeatherModel::queryWeather(int townNum){
    //the network manager will post and recieve our HTTP requests
    QNetworkAccessManager *manager = new QNetworkAccessManager(this);

    //the host of the webservice
    QUrl url("http://openweathermap.org/data/2.5/weather");

    //set up the request to post
    QNetworkRequest request(url);
    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");

    //the additional query data to enter
    QUrlQuery query(url);
    query.addQueryItem("APPID","291cc02999b830ce1d7bf176d3d49172"); //our CS3307 APPID
    query.addQueryItem("q", _townList.at(townNum) + ",can");
    query.addQueryItem("units", "metric");
    url.setQuery(query);

    //update the request with the new query information.
    request.setUrl(url);

    //post the request
    manager->post(request, url.toEncoded());

    //connect the "finished" signal from the manager to our response handling method
    QObject::connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(replyFinished(QNetworkReply *)));
}
开发者ID:Flyte27,项目名称:Personal-Work,代码行数:31,代码来源:weathermodel.cpp

示例2: exec

QByteArray QWget::exec(QUrl url, QByteArray postData)
{
    QNetworkAccessManager * manager = network_manager();
    manager->setProxy(_proxy);
    connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(onFinished(QNetworkReply*)));
    QNetworkRequest * nr = new QNetworkRequest(url);
    //nr->setRawHeader("User-Agent","Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1");
    nr->setRawHeader("User-Agent","Opera/9.0");
    qDebug() << url;

    finished = false;
    if(postData.isNull())
        manager->get(*nr);
    else
        manager->post(*nr,postData);
    while(!finished)
    {
        QCoreApplication::instance()->processEvents();
        #ifdef WIN32
        Sleep(50);
        #else
            usleep(50000);
        #endif
    }
    delete nr;
    QCoreApplication::instance()->processEvents();
    //qDebug() << "Ans: " << ans;
    // delete nr;
    return ans;
    return QByteArray();
}
开发者ID:trousev,项目名称:qwget,代码行数:31,代码来源:qwget.cpp

示例3: post

QNetworkReply::NetworkError NetworkServiceAccessor::post(const QNetworkRequest &request, const QByteArray &data, QByteArray &replyData) const
{
    QNetworkReply::NetworkError result = QNetworkReply::NoError;
    QFuture<void> future = QtConcurrent::run(QThreadPool::globalInstance(), [&](){
        QEventLoop loop;
        QNetworkAccessManager networkAccessManager;
        QNetworkReply *reply = networkAccessManager.post(request, data);

        connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
        LoggingManager::getSingleton().log() << "NetworkService Post: " << request.url().toString();
        qDebug() << "NetworkService Post: " << request.url().toString();
        LoggingManager::getSingleton().log() << "Payload: " << QString::fromUtf8(data);
        qDebug() << "Payload: " << QString::fromUtf8(data);
        loop.exec();

        result = reply->error();

        if (result != QNetworkReply::NoError)
        {
            qDebug() << "Network Service Accessor Error: " << reply->errorString();
            LoggingManager::getSingleton().log() << "NetworkService: " << reply->errorString();
        }

        replyData = reply->readAll();
        qDebug() << replyData;
        reply->deleteLater();
    });

    future.waitForFinished();
    return result;
}
开发者ID:shi-yan,项目名称:Swiftly,代码行数:31,代码来源:NetworkServiceAccessor.cpp

示例4: addMessage

/*
 * Add message request set
 */
void ElisaServer::addMessage(QString body, double latitude, double longitude)
{
    //check if user is already logged
    if(m_nickname!=""){
        QNetworkAccessManager *manager = new QNetworkAccessManager(this);

        //set urls
        QUrl url;
        url.setUrl("http://projectelisa.altervista.org/main/post/?x="+QString::number(latitude,'g',10)+"&y="+QString::number(longitude,'g',10)+"&z=0&nick="+temp_nickname+"&pass="+temp_password);

        //add post params
        QByteArray postData;
        postData.append("body="+body);

        //bind network request
        QNetworkRequest request;
        request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
        request.setUrl(url);

        //define callback
        QNetworkReply * r;
        r = manager->post(request, postData);
        connect(r,SIGNAL(finished()),this,SLOT(addMessageFinished()));
    } else {
        emit addMessageReply("denied");
    }

}
开发者ID:LucaFos,项目名称:projectelisa-qt,代码行数:31,代码来源:elisaserver.cpp

示例5: addFeed

/*!
\brief Subscribe new feed
*/
void GoogleReader::addFeed(QString feedAddress, QString feedName, QString feedLabel) {
    qDebug() << "GoogleReader::addFeed(" << feedAddress << "," << feedName << "," << feedLabel << ")";

    if (_googleCookie == NULL) {
        emit signalConnected(false);
        this->login();
    }

    if (feedAddress.left(7) != "http://")
        feedAddress.insert(0, "http://");

    QString url = "http://www.google.com/reader/api/0/subscription/edit?client=GooDer";
    QString postData = "";

    if (feedName.isEmpty() && feedLabel.isEmpty()) {
        postData = QString("s=feed/%1&ac=subscribe&T=%2").arg(feedAddress, _googleToken);
    } else if (!feedName.isEmpty() && feedLabel.isEmpty()) {
        postData = QString("s=feed/%1&ac=subscribe&t=%2&T=%3").arg(feedAddress, feedName, _googleToken);
    } else if (!feedName.isEmpty() && !feedLabel.isEmpty()) {
        postData = QString("s=feed/%1&ac=subscribe&t=%2&a=user/-/label/%3&T=%4").arg(feedAddress, feedName, feedLabel, _googleToken);
    } else if (feedName.isEmpty() && !feedLabel.isEmpty()) {
        postData = QString("s=feed/%1&ac=subscribe&a=user/-/label/%2&T=%3").arg(feedAddress, feedLabel, _googleToken);
    }

    QNetworkAccessManager* feedConnection = new QNetworkAccessManager(this);

    QNetworkRequest postRequest = QNetworkRequest(QUrl(url));
    postRequest.setRawHeader("Authorization", _googleCookie->value());
    postRequest.setRawHeader("Content-Type", "application/x-www-form-urlencoded");

    connect(feedConnection, SIGNAL(finished(QNetworkReply*)),
            this, SLOT(parseAddFeed(QNetworkReply *)));

    feedConnection->post(postRequest, postData.toAscii());
}
开发者ID:tpopela,项目名称:GooDer,代码行数:38,代码来源:googleReader.cpp

示例6: 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

示例7: connect

void
StravaUploadDialog::requestLogin()
{
    progressLabel->setText(tr("Login..."));
    progressBar->setValue(5);

    QString username = appsettings->cvalue(mainWindow->cyclist, GC_STRUSER).toString();
    QString password = appsettings->cvalue(mainWindow->cyclist, GC_STRPASS).toString();

    QNetworkAccessManager networkMgr;
    QEventLoop eventLoop;
    connect(&networkMgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(requestLoginFinished(QNetworkReply*)));
    connect(&networkMgr, SIGNAL(finished(QNetworkReply *)), &eventLoop, SLOT(quit()));

    QByteArray data;
    /*data += "{\"email\": \"" + username + "\",";
    data += "\"password\": \"" + password + "\",";
    data += "\"agreed_to_terms\": \"true\"}";*/

    QUrl params;

    params.addQueryItem("email", username);
    params.addQueryItem("password",password);
    params.addQueryItem("agreed_to_terms", "true");
    data = params.encodedQuery();

    QUrl url = QUrl( STRAVA_URL_SSL + "/authentication/login");
    QNetworkRequest request = QNetworkRequest(url);
    //request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");

    request.setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded");

    networkMgr.post( request, data);
    eventLoop.exec();
}
开发者ID:27sparks,项目名称:GoldenCheetah,代码行数:35,代码来源:StravaUploadDialog.cpp

示例8: accept

void TwitPicDialog::accept() {
	m_progressBar->reset();
	m_errorMsgLabel->hide();
	m_progressBar->show();
	QUrl url("http://twitpic.com/api/upload");
	QNetworkRequest post(url);
	QByteArray boundary = "------------------------------7251e57fe7ed"; // "--------dlf-maximum";
	post.setHeader(QNetworkRequest::ContentTypeHeader, "multipart/form-data; boundary=" + boundary);
	post.setRawHeader("Host", "twitpic.com");
	QByteArray ba;
	ba.append("--" + boundary + "\r\n");
	ba.append("Content-Disposition: form-data; name=\"media\"; filename=\"1.jpg\"\r\n");
	ba.append("Content-Type: image/" + QImageReader::imageFormat(m_fileName) + "\r\n\r\n");
	QFile file(m_fileName);
	file.open(QIODevice::ReadOnly);
	ba.append(file.readAll());
	ba.append("\r\n");
	ba.append("--" + boundary + "\r\n");
	ba.append("Content-Disposition: form-data; name=\"username\"\r\n\r\n");
	ba.append(m_username + "\r\n");
	ba.append("--" + boundary + "\r\n");
	ba.append("Content-Disposition: form-data; name=\"password\"\r\n\r\n");
	ba.append(m_password + "\r\n");
	ba.append("--" + boundary + "--" + "\r\n");
	post.setHeader(QNetworkRequest::ContentLengthHeader, ba.count());

	QNetworkAccessManager *manager = new QNetworkAccessManager(this);
	m_reply = manager->post(post, ba);
	connect(m_reply, SIGNAL(uploadProgress(qint64, qint64)), this, SLOT(updateProgressBar(qint64,qint64)));
	connect(m_reply, SIGNAL(finished()), this, SLOT(uploadFinished()));
	m_postButton->setEnabled(false);
}
开发者ID:roop,项目名称:qwit,代码行数:32,代码来源:TwitPicDialog.cpp

示例9: process

void KDSoapThreadTask::process(QNetworkAccessManager& accessManager)
{
    // Can't use m_iface->asyncCall, it would use the accessmanager from the main thread
    //KDSoapPendingCall pendingCall = m_iface->asyncCall(m_method, m_message, m_action);

    //Headers should be always qualified
    for (KDSoapHeaders::Iterator it = m_data->m_headers.begin(); it != m_data->m_headers.end(); ++it) {
        it->setQualified(true);
    }

#if QT_VERSION >= 0x040700
    QNetworkCookieJar* jar = m_data->m_iface->d->accessManager()->cookieJar();
    // Qt-4.6: this aborts in setParent(this) because the jar is from another thread
    // Qt-4.7: it's from a different thread, so this won't change the parent object
    accessManager.setCookieJar(jar);
#endif

    accessManager.setProxy( m_data->m_iface->d->accessManager()->proxy() );

    QBuffer* buffer = m_data->m_iface->d->prepareRequestBuffer(m_data->m_method, m_data->m_message, m_data->m_headers);
    QNetworkRequest request = m_data->m_iface->d->prepareRequest(m_data->m_method, m_data->m_action);
    QNetworkReply* reply = accessManager.post(request, buffer);
    m_data->m_iface->d->setupReply(reply);
    KDSoapPendingCall pendingCall(reply, buffer);

    KDSoapPendingCallWatcher *watcher = new KDSoapPendingCallWatcher(pendingCall, this);
    connect(watcher, SIGNAL(finished(KDSoapPendingCallWatcher*)),
            this, SLOT(slotFinished(KDSoapPendingCallWatcher*)));
}
开发者ID:hporten,项目名称:KDSoap,代码行数:29,代码来源:KDSoapClientThread.cpp

示例10: sendReportUsingGithub

/**
 * @fn sendReportUsingGithub
 */
void GithubModule::sendReportUsingGithub(const QMap<QString, QString> info)
{
    if (debug) qDebug() << "[GithubModule]" << "[sendReportUsingGithub]";

    // authentication
    QString headerData;
    if (info.contains(QString("userdata")))
        headerData = QString("token ") + info[QString("userdata")];
    else {
        QString concatenated = info[QString("username")] + QString(":") + info[QString("password")];
        QByteArray userData = concatenated.toLocal8Bit().toBase64();
        headerData = QString("Basic ") + userData;
    }
    // text
    QByteArray text = prepareRequest(info[QString("title")], info[QString("body")]);
    QByteArray textSize = QByteArray::number(text.size());
    // sending request
    QNetworkRequest request = QNetworkRequest(parseString(dynamic[QString("ISSUES_URL")]));
    request.setRawHeader("Authorization", headerData.toLocal8Bit());
    request.setRawHeader("User-Agent", "reportabug");
    request.setRawHeader("Host", "api.github.com");
    request.setRawHeader("Accept", "*/*");
    request.setRawHeader("Content-Type", "application/vnd.github.VERSION.raw+json");
    request.setRawHeader("Content-Length", textSize);
    QNetworkAccessManager *manager = new QNetworkAccessManager;
    manager->post(request, text);
    disconnect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(githubFinished(QNetworkReply *)));
    connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(githubFinished(QNetworkReply *)));
}
开发者ID:arcan1s,项目名称:reportabug,代码行数:32,代码来源:githubmodule.cpp

示例11: send_query

QJsonObject festrip_api::send_query(bool query_type, QUrlQuery query)
{
  // create custom temporary event loop on stack
  QEventLoop eventLoop;

  // "quit()" the event-loop, when the network request "finished()"
  QNetworkAccessManager mgr;
  QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));

  // the HTTP request
  QNetworkRequest req = QNetworkRequest(QUrl(query));
  if (GET == query_type) {
    QNetworkReply *reply = mgr.get(req);
  } else {
    QNetworkReply *reply = mgr.post(req);
  }
  eventLoop.exec(); // blocks stack until "finished()" has been called

  if (QNetworkReply::NoError == reply->error()) {
   //success
   qDebug() << "Success " <<reply->readAll();
  } else {
   //failure
   qDebug() << "Failure " <<reply->errorString();
   qDebug() << "Request: " << reply->url();
  }
  delete reply;
  // return((QJsonObject)reply->readAll());
}
开发者ID:nachootal,项目名称:sailtrip,代码行数:29,代码来源:festrip_api.cpp

示例12: main

int main(int argc, char **argv) {
    QCoreApplication app(argc, argv);
    
    QNetworkAccessManager *manager = new QNetworkAccessManager;
    QObject::connect(manager, &QNetworkAccessManager::finished, [=](QNetworkReply *reply) {
        QJsonParseError error;
        QJsonDocument doc2 = QJsonDocument::fromJson(reply->readAll(), &error);
        qDebug()<<doc2.toJson();

        reply-> deleteLater();
        qApp->quit();
    }); 
    
    QNetworkRequest request(QUrl("http://demo.gitlab.com/api/v3/user/keys"));
    //request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
    request.setRawHeader("PRIVATE-TOKEN", "xD2u7qqskGczXKZ7Mum9");
    
    //QByteArray data = R"json({"email":"[email protected]", "password":"123456"})json";
    QByteArray data = R"json({"title":"test", "key":"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDXpNlgbh36Lfryc5ftLWYf/tkg/jBzanyAAyDOEBZtukfCsgxsBh87MlTkLyE7f9QT2/TQAB8r1Qx9ZdvkNAFkTAZgkV4BZA9+CiPYv/THZ+KGBCWEnNZcS0+kh7Y3BLmzsMduS/0XkJQF9Wn+v7em5caY3//oCy3iT2sBMOnFSPE9xCqdM+w31sX7TM9sprgjVSoCLfBdlXdoStVn9UsJHxrHTLL0TzeDHWx2Aiqn/2CP2zsEj8fp1VDXVfzNe/0knaHq7WqN5NaCZEpa3EbuimK7i+65gcHS6UfGZ0NMqwn9MA95TLK3zVqvmw62VAj1QEa58XLZh/7y1AlHIYav [email protected]"})json";
    manager->post(request, data);
    //manager->get(request);

    return app.exec();
}
开发者ID:chideat,项目名称:gitX-lib,代码行数:25,代码来源:main.cpp

示例13: pushSales

void DeviceAccess::pushSales()
{

    QByteArray data;
    QNetworkAccessManager *manager = new QNetworkAccessManager(this);
    connect(manager, SIGNAL(finished(QNetworkReply*)),
            this, SLOT(replypushsalescomplete(QNetworkReply *)));
    for(int i = 0; i < sales.size(); i++)
    {

    string s = sales.at(i).value("item").toStdString();
    s.erase(
        remove( s.begin(), s.end(), '\"' ),
        s.end()
        );
    QNetworkRequest request;
    request.setUrl(QUrl("http://vergeapp.com/api/v2/addsales.json"));
    QUrlQuery params;
    params.addQueryItem("firm", firm);
    params.addQueryItem("outlet", outlet);
    params.addQueryItem("product_name", QString::fromStdString(s));
    params.addQueryItem("price", sales.at(i).value("price"));
    params.addQueryItem("quantity", sales.at(i).value("qty"));
    params.addQueryItem("reorder", "1");
    params.addQueryItem("cost", "2");
    qDebug() << params.toString();
    manager->post(request, data.append(params.toString()));
    }


}
开发者ID:mekkah,项目名称:QuorionUpdater,代码行数:31,代码来源:deviceaccess.cpp

示例14: sendGoogleReq

void MyEngine::sendGoogleReq(const QString &msg) {
    qDebug() << "Called the sendGoogleReq method with " << msg;

    QNetworkAccessManager *manager = new QNetworkAccessManager(this);
    connect(manager, SIGNAL(finished(QNetworkReply*)),
            this, SLOT(replyFinished(QNetworkReply*)));

    //manager->get(QNetworkRequest(QUrl("http://qt.nokia.com")));
    //QNetworkRequest myReq = QNetworkRequest(QUrl("https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&lang=en-US"));
    // myReq.setHeader(QNetworkRequest::ContentTypeHeader, "audio/pcm; rate=8000");

    QNetworkRequest myReq = QNetworkRequest(QUrl("https://www.google.com/speech-api/v1/recognize?xjerr=1&client=test&lang=pl-PL"));
    myReq.setHeader(QNetworkRequest::ContentTypeHeader, "audio/x-flac; rate=8000");

    //req.setHeader(QNetworkRequest::ContentTypeHeader, "");
    //open audio file to send
    qDebug() << "Sending file: " << flacFilePath;
    QFile file(flacFilePath);
    if (file.exists()) {
        file.open(QIODevice::ReadOnly)?qDebug() << "file opened: " << flacFilePath:qCritical() << "file open error: " << flacFilePath;
        QByteArray data = file.readAll();
        // myReq.setRawHeader("Content", data);
        manager->post(myReq, data);
    }

}
开发者ID:biedro,项目名称:s2c,代码行数:26,代码来源:myengine.cpp

示例15: process

void Eyrie::process() {
	if(recbin == NULL) {
		return;
	}
	if(GST_BUFFER_SIZE(buf) == 0) {
		endRecording();
		QVariant ret;
		QMetaObject::invokeMethod(parent(), "setStatus", Q_RETURN_ARG(QVariant, ret), Q_ARG(QVariant, "Sorry, the recording failed."));
		return;
	}
	mutex->lock();
	const float *pcm = (const float *) GST_BUFFER_DATA(buf);
	Codegen *codegen = new Codegen(pcm, GST_BUFFER_SIZE(buf) / sizeof(float), 0);
	mutex->unlock();
	std::string code = codegen->getCodeString();
	QNetworkAccessManager *networkManager = new QNetworkAccessManager();
	QUrl url("http://developer.echonest.com/api/v4/song/identify");
	QByteArray params;
	params.append("api_key=RIUKSNTIPKUMPHPEO");
	params.append("&query=[{\"metadata\":{\"version\":4.12},\"code\":\""); params.append(code.c_str()); params.append("\"}]");
	QNetworkRequest request;
	request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded;charset=UTF-8");
	request.setUrl(url);
	connect(networkManager, SIGNAL(finished(QNetworkReply *)), this, SLOT(parseResponse(QNetworkReply *)));
	networkManager->post(request, params);
}
开发者ID:Alex237,项目名称:eyrie,代码行数:26,代码来源:eyrie.cpp


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