本文整理汇总了C++中QUrlQuery::encodedQuery方法的典型用法代码示例。如果您正苦于以下问题:C++ QUrlQuery::encodedQuery方法的具体用法?C++ QUrlQuery::encodedQuery怎么用?C++ QUrlQuery::encodedQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QUrlQuery
的用法示例。
在下文中一共展示了QUrlQuery::encodedQuery方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: toStdString
static std::string qUrlQueryToPostData(const QUrlQuery & query) {
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
return toStdString(query.encodedQuery());
#else
return toUTF8(query.query(QUrl::FullyEncoded));
#endif
}
示例2: login
void GagBookManager::login(const QString &username, const QString &password)
{
Q_ASSERT(m_netManager);
if (m_loginReply != 0) {
m_loginReply->disconnect();
m_loginReply->deleteLater();
m_loginReply = 0;
}
if (m_isBusy != true) {
m_isBusy = true;
emit busyChanged();
}
QByteArray postData;
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
QUrlQuery postDataQuery;
postDataQuery.addQueryItem("username", username);
postDataQuery.addQueryItem("password", password);
postData = postDataQuery.toString(QUrl::FullyEncoded).toUtf8();
#else
QUrl postDataQuery;
postDataQuery.addQueryItem("username", username);
postDataQuery.addQueryItem("password", password);
postData = postDataQuery.encodedQuery();
#endif
m_loginReply = m_netManager->createPostRequest(QUrl("https://9gag.com/login"), postData);
connect(m_loginReply, SIGNAL(finished()), SLOT(onLoginFinished()));
}
示例3: respond
bool QXmppSaslClientFacebook::respond(const QByteArray &challenge, QByteArray &response)
{
if (m_step == 0) {
// no initial response
response = QByteArray();
m_step++;
return true;
} else if (m_step == 1) {
// parse request
#if QT_VERSION >= 0x050000
QUrlQuery requestUrl(challenge);
#else
QUrl requestUrl;
requestUrl.setEncodedQuery(challenge);
#endif
if (!requestUrl.hasQueryItem("method") || !requestUrl.hasQueryItem("nonce")) {
warning("QXmppSaslClientFacebook : Invalid challenge, nonce or method missing");
return false;
}
// build response
#if QT_VERSION >= 0x050000
QUrlQuery responseUrl;
#else
QUrl responseUrl;
#endif
responseUrl.addQueryItem("access_token", password());
responseUrl.addQueryItem("api_key", username());
responseUrl.addQueryItem("call_id", 0);
responseUrl.addQueryItem("method", requestUrl.queryItemValue("method"));
responseUrl.addQueryItem("nonce", requestUrl.queryItemValue("nonce"));
responseUrl.addQueryItem("v", "1.0");
#if QT_VERSION >= 0x050000
response = responseUrl.query().toUtf8();
#else
response = responseUrl.encodedQuery();
#endif
m_step++;
return true;
} else {
warning("QXmppSaslClientFacebook : Invalid step");
return false;
}
}
示例4: HttpRequest
bool CetonStreamHandler::HttpRequest(
const QString &method, const QString &script,
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
const QUrl ¶ms,
#else
const QUrlQuery ¶ms,
#endif
QString &response, uint &status_code) const
{
QUrl url;
QNetworkRequest *request = new QNetworkRequest();
QByteArray data;
MythDownloadManager *manager = GetMythDownloadManager();
url.setScheme("http");
url.setHost(_ip_address);
url.setPath(script);
// Specify un-cached access to the device
// The next two lines are automagically added by Qt
// request->setRawHeader("Cache-Control", "no-cache");
// request->setRawHeader("Pragma", "no-cache");
request->setAttribute(QNetworkRequest::CacheLoadControlAttribute,
QNetworkRequest::AlwaysNetwork);
if ("GET" == method)
{
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
url.setEncodedQuery(params.encodedQuery());
#else
url.setQuery(params);
#endif
request->setUrl(url);
if (manager->download(request, &data))
{
response = QString(data);
status_code = 200;
return true;
}
else
{
response = "Download failed";
status_code = 500;
return false;
}
}
else if ("POST" == method)
{
request->setUrl(url);
request->setHeader(QNetworkRequest::ContentTypeHeader,
"application/x-www-form-urlencoded");
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
data = params.encodedQuery();
#else
data = params.query(QUrl::FullyEncoded).toUtf8();
#endif
// Next line automagically added by Qt
// request->setHeader(QNetworkRequest::ContentLengthHeader, data.size());
if (manager->post(request, &data))
{
response = QString(data);
status_code = 200;
return true;
}
else
{
response = "Download failed";
status_code = 500;
return false;
}
}
delete request;
response = "Unsupported HttpRequest method";
status_code = 500;
return false;
}
示例5: download
QScriptValue Web::download(const QString &urlString, const QScriptValue &options)
{
mData.clear();
if(mFileValue.isValid())
{
if(Code::File *file = qobject_cast<Code::File*>(mFileValue.toQObject()))
mFile = file->file();
else
mFile = new QFile(mFileValue.toString(), this);
mCloseFile = false;
if(!mFile->isOpen())
{
if(!mFile->open(QIODevice::WriteOnly))
{
throwError("OpenFileError", tr("Unable to open the destination file"));
return thisObject();
}
mCloseFile = true;
}
}
QUrl url(urlString);
if(url.scheme() == QString())
url = QUrl("http://" + urlString, QUrl::TolerantMode);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
QUrlQuery urlQuery;
#endif
QNetworkRequest request;
QScriptValueIterator it(options);
Method method = Get;
QByteArray postData;
while(it.hasNext())
{
it.next();
if(it.name() == "rawHeaders")
{
QScriptValueIterator headerIt(it.value());
while(headerIt.hasNext())
{
headerIt.next();
request.setRawHeader(headerIt.name().toUtf8(), headerIt.value().toString().toUtf8());
}
}
else if(it.name() == "method")
{
method = static_cast<Method>(it.value().toInt32());
}
else if(it.name() == "postData")
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
QScriptValueIterator postDataIt(it.value());
QUrlQuery postDataParameters;
while(postDataIt.hasNext())
{
postDataIt.next();
postDataParameters.addQueryItem(postDataIt.name(), postDataIt.value().toString());
}
postData = postDataParameters.toString(QUrl::FullyEncoded).toLatin1();
#else
QScriptValueIterator postDataIt(it.value());
QUrl postDataParameters;
while(postDataIt.hasNext())
{
postDataIt.next();
postDataParameters.addQueryItem(postDataIt.name(), postDataIt.value().toString());
}
postData = postDataParameters.encodedQuery();
#endif
}
else if(it.name() == "query")
{
QScriptValueIterator queryIt(it.value());
while(queryIt.hasNext())
{
queryIt.next();
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
urlQuery.addQueryItem(queryIt.name(), queryIt.value().toString());
#else
url.addQueryItem(queryIt.name(), queryIt.value().toString());
#endif
}
//.........这里部分代码省略.........
示例6: validatePage
bool NewAccountPage::validatePage()
{
if(hasCreatedAccount)
{
return true;
}
serverQueryFinished = false;
serverQueryError = false;
//Check if passwords match
if(input_password->text() != input_confirmPassword->text())
{
label_message->setText(tr("<font color='red'>Passwords do not match</font>"));
return false;
}
label_message->setText("Creating account...");
QUrl baseUrl( "https://api.screencloud.net/1.0/users/register.xml" );
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
QUrlQuery query(baseUrl);
#else
QUrl query(baseUrl);
#endif
query.addQueryItem("oauth_version", "1.0");
query.addQueryItem("oauth_signature_method", "PLAINTEXT");
query.addQueryItem("oauth_consumer_key", CONSUMER_KEY_SCREENCLOUD);
query.addQueryItem("oauth_signature", CONSUMER_SECRET_SCREENCLOUD);
query.addQueryItem("oauth_timestamp", QString::number(QDateTime::currentDateTimeUtc().toTime_t()));
query.addQueryItem("oauth_nonce", NetworkUtils::generateNonce(15));
// create a request parameters map
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
QUrlQuery bodyParams;
#else
QUrl bodyParams;
#endif
bodyParams.addQueryItem("data[User][email]", input_email->text());
bodyParams.addQueryItem("data[User][password]", input_password->text());
bodyParams.addQueryItem("data[User][password_confirmation]", input_confirmPassword->text());
// construct the body string
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
QByteArray body = bodyParams.query(QUrl::FullyEncoded).toUtf8();
#else
QByteArray body = bodyParams.encodedQuery();
#endif
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
QUrl fullUrl(baseUrl);
fullUrl.setQuery(query);
#else
QUrl fullUrl(query);
#endif
QNetworkRequest request;
request.setUrl(fullUrl);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
manager->post(request, body);
while (!serverQueryFinished) {
qApp->processEvents(QEventLoop::WaitForMoreEvents);
}
if(serverQueryError)
{
return false;
}
hasCreatedAccount = true;
return true;
}