本文整理汇总了C++中QUrl::setEncodedQuery方法的典型用法代码示例。如果您正苦于以下问题:C++ QUrl::setEncodedQuery方法的具体用法?C++ QUrl::setEncodedQuery怎么用?C++ QUrl::setEncodedQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QUrl
的用法示例。
在下文中一共展示了QUrl::setEncodedQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setEncodedQuery
int Url::setEncodedQuery ( lua_State * L )// ( const QByteArray & query )
{
QUrl* lhs = ValueInstaller2<QUrl>::check( L, 1 );
//QByteArray* query = ValueInstaller2<QByteArray>::check( L, 2 );
lhs->setEncodedQuery( Util::toStr( L, 2 ) );
return 0;
}
示例2: post
/** Returns the POST data for the given \a key.
*/
QString QDjangoHttpRequest::post(const QString &key) const
{
QByteArray buffer = d->buffer;
buffer.replace('+', ' ');
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
QUrlQuery query(QString::fromUtf8(buffer));
return query.queryItemValue(key, QUrl::FullyDecoded);
#else
QUrl url;
url.setEncodedQuery(buffer);
return url.queryItemValue(key);
#endif
}
示例3: get
/** Returns the GET data for the given \a key.
*/
QString QDjangoHttpRequest::get(const QString &key) const
{
QString queryString = d->meta.value(QLatin1String("QUERY_STRING"));
queryString.replace('+', ' ');
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
QUrlQuery query(queryString);
return query.queryItemValue(key, QUrl::FullyDecoded);
#else
QUrl url;
url.setEncodedQuery(queryString.toLatin1());
return url.queryItemValue(key);
#endif
}
示例4: proxiedRequest
bool Pillow::HttpHandlerProxy::handleRequest(Pillow::HttpConnection *request)
{
if (_proxiedUrl.isEmpty()) return false;
QUrl targetUrl = _proxiedUrl;
targetUrl.setEncodedPath(request->requestPath());
if (!request->requestQueryString().isEmpty()) targetUrl.setEncodedQuery(request->requestQueryString());
if (!request->requestFragment().isEmpty()) targetUrl.setEncodedFragment(request->requestFragment());
QNetworkRequest proxiedRequest(targetUrl);
foreach (const Pillow::HttpHeader& header, request->requestHeaders())
proxiedRequest.setRawHeader(header.first, header.second);
createPipe(request, createProxiedReply(request, proxiedRequest));
return true;
}
示例5: 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;
}
}
示例6: userTokenRequestCompleted
void NetFlixAuthProxy::userTokenRequestCompleted(int retCode, QString body)
{
qDebug() << "user token completed!!";
qDebug() << retCode;
qDebug() << body;
QUrl parser;
parser.setEncodedQuery(body.toUtf8());
QString user_id = parser.queryItemValue(STR(OAUTH_USER_ID));
QString token = parser.queryItemValue(STR(OAUTH_TOKEN));
QString token_secret = parser.queryItemValue(STR(OAUTH_TOKEN_SECRET));
settings->setUserId(user_id);
settings->setOAuthToken(token);
settings->setOAuthTokenSecret(token_secret);
emit getUserTokenSucceeded();
}
示例7: makeCacheKey
static QByteArray makeCacheKey(QUrl &url, QNetworkProxy *proxy)
{
QByteArray result;
QUrl copy = url;
bool isEncrypted = copy.scheme().toLower() == QLatin1String("https");
copy.setPort(copy.port(isEncrypted ? 443 : 80));
result = copy.toEncoded(QUrl::RemoveUserInfo | QUrl::RemovePath |
QUrl::RemoveQuery | QUrl::RemoveFragment);
#ifndef QT_NO_NETWORKPROXY
if (proxy && proxy->type() != QNetworkProxy::NoProxy) {
QUrl key;
switch (proxy->type()) {
case QNetworkProxy::Socks5Proxy:
key.setScheme(QLatin1String("proxy-socks5"));
break;
case QNetworkProxy::HttpProxy:
case QNetworkProxy::HttpCachingProxy:
key.setScheme(QLatin1String("proxy-http"));
break;
default:
break;
}
if (!key.scheme().isEmpty()) {
key.setUserName(proxy->user());
key.setHost(proxy->hostName());
key.setPort(proxy->port());
key.setEncodedQuery(result);
result = key.toEncoded();
}
}
#else
Q_UNUSED(proxy)
#endif
return "http-connection:" + result;
}
示例8: createUrl
QUrl createUrl(const char *urlData, const http_parser_url &urlInfo)
{
QUrl url;
url.setScheme(CHECK_AND_GET_FIELD(urlData, urlInfo, UF_SCHEMA));
url.setHost(CHECK_AND_GET_FIELD(urlData, urlInfo, UF_HOST));
// Port is dealt with separately since it is available as an integer.
url.setPath(CHECK_AND_GET_FIELD(urlData, urlInfo, UF_PATH));
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
url.setQuery(CHECK_AND_GET_FIELD(urlData, urlInfo, UF_QUERY));
#else
if (HAS_URL_FIELD(urlInfo, UF_QUERY)) {
url.setEncodedQuery(QByteArray(urlData + urlInfo.field_data[UF_QUERY].off,
urlInfo.field_data[UF_QUERY].len));
}
#endif
url.setFragment(CHECK_AND_GET_FIELD(urlData, urlInfo, UF_FRAGMENT));
url.setUserInfo(CHECK_AND_GET_FIELD(urlData, urlInfo, UF_USERINFO));
if (HAS_URL_FIELD(urlInfo, UF_PORT))
url.setPort(urlInfo.port);
return url;
}
示例9: loginUrlRequestCompleted
void NetFlixAuthProxy::loginUrlRequestCompleted(int retCode, QString body)
{
qDebug() << "temp token completed!!";
qDebug() << retCode;
qDebug() << body;
QUrl parser;
parser.setEncodedQuery(body.toUtf8());
QString url = parser.queryItemValue(STR(NETFLIX_LOGIN_URL_PARAM));
parser.removeQueryItem(STR(NETFLIX_LOGIN_URL_PARAM));
QString token = parser.queryItemValue(STR(OAUTH_TOKEN));
QString token_secret = parser.queryItemValue(STR(OAUTH_TOKEN_SECRET));
parser.removeQueryItem(STR(OAUTH_TOKEN_SECRET));
settings->setOAuthToken(token);
settings->setOAuthTokenSecret(token_secret);
QUrl loginUrl = QUrl(url);
loginUrl.setEncodedQueryItems(parser.encodedQueryItems());
qDebug() << loginUrl.toEncoded();
emit getTokenUrlSucceeded(loginUrl);
}
示例10: sendMessage
void OmaSaunalahti::sendMessage(QNetworkAccessManager* manager, QString message) {
if (message.toAscii().length()==0)
return;
this->loggedIn = false;
connect(manager, SIGNAL(finished(QNetworkReply*)), SLOT(replyFinished(QNetworkReply*)));
this->message = message;
this->messageTime = QString("%0 %1").arg(QDate::currentDate().toString("dd.MM.yyyy")).arg(QTime::currentTime().toString("hh:mm:ss.zzz"));
QChar *messageChar = this->message.data();
while (!messageChar->isNull()) {
if (messageChar->isSpace()) {
QString chr = QString("%0").arg(QString::number( messageChar->toAscii(), 16 ).toUpper());
if (chr.length()==1)
chr = "%0" + chr;
this->message = this->message.replace(messageChar->toAscii(),chr);
}
++messageChar;
}
QUrl url = QUrl(this->server);
url.addQueryItem("username",this->username);
url.addQueryItem("login","Sisään");
url.addQueryItem("password",this->password);
QNetworkRequest request;
request.setUrl(url);
QNetworkReply *reply = manager->post(request,url.toString().split("?")[1].toAscii());
url.setEncodedQuery(QByteArray());
url.addQueryItem("sender",this->sender);
url.addQueryItem("recipients",this->receiver);
url.addQueryItem("text",this->message);
url.addQueryItem("size",QString("%0").arg(this->message.toAscii().length()));
url.addQueryItem("send","Lähetä");
connect(manager, SIGNAL(finished(QNetworkReply*)), SLOT(messageSent(QNetworkReply*)));
reply = manager->post(request,url.toString().split("?")[1].toAscii());
}
示例11: 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;
}
示例12: parseContent
bool RequestParser::parseContent(const QByteArray& data)
{
// Parse message content
qDebug() << Q_FUNC_INFO << "Content-Length: " << m_request.headers["content-length"];
qDebug() << Q_FUNC_INFO << "data.size(): " << data.size();
// Parse url-encoded POST data
if (m_request.headers["content-type"].startsWith("application/x-www-form-urlencoded")) {
QUrl url;
#ifndef QBT_USES_QT5
url.setEncodedQuery(data);
QListIterator<QPair<QString, QString> > i(url.queryItems());
#else
url.setQuery(data);
QListIterator<QPair<QString, QString> > i(QUrlQuery(url).queryItems(QUrl::FullyDecoded));
#endif
while (i.hasNext()) {
QPair<QString, QString> pair = i.next();
m_request.posts[pair.first.toLower()] = pair.second;
}
return true;
}
// Parse multipart/form data (torrent file)
/**
data has the following format (if boundary is "cH2ae0GI3KM7GI3Ij5ae0ei4Ij5Ij5")
--cH2ae0GI3KM7GI3Ij5ae0ei4Ij5Ij5
Content-Disposition: form-data; name=\"Filename\"
PB020344.torrent
--cH2ae0GI3KM7GI3Ij5ae0ei4Ij5Ij5
Content-Disposition: form-data; name=\"torrentfile"; filename=\"PB020344.torrent\"
Content-Type: application/x-bittorrent
BINARY DATA IS HERE
--cH2ae0GI3KM7GI3Ij5ae0ei4Ij5Ij5
Content-Disposition: form-data; name=\"Upload\"
Submit Query
--cH2ae0GI3KM7GI3Ij5ae0ei4Ij5Ij5--
**/
QString content_type = m_request.headers["content-type"];
if (content_type.startsWith("multipart/form-data")) {
const QRegExp boundaryRegexQuoted("boundary=\"([ \\w'()+,-\\./:=\\?]+)\"");
const QRegExp boundaryRegexNotQuoted("boundary=([\\w'()+,-\\./:=\\?]+)");
QByteArray boundary;
if (boundaryRegexQuoted.indexIn(content_type) < 0) {
if (boundaryRegexNotQuoted.indexIn(content_type) < 0) {
qWarning() << "Could not find boundary in multipart/form-data header!";
return false;
}
else {
boundary = "--" + boundaryRegexNotQuoted.cap(1).toLatin1();
}
}
else {
boundary = "--" + boundaryRegexQuoted.cap(1).toLatin1();
}
qDebug() << "Boundary is " << boundary;
QList<QByteArray> parts = splitMultipartData(data, boundary);
qDebug() << parts.size() << "parts in data";
foreach (const QByteArray& part, parts) {
if (!parseFormData(part))
return false;
}
return true;
}
qWarning() << Q_FUNC_INFO << "unknown content type:" << qPrintable(content_type);
return false;
}
示例13: loading
bool
AudioEngine::loadTrack( const Tomahawk::result_ptr& result )
{
bool err = false;
{
QSharedPointer<QIODevice> io;
if ( result.isNull() )
err = true;
else
{
setCurrentTrack( result );
if ( !isHttpResult( m_currentTrack->url() ) && !isLocalResult( m_currentTrack->url() ) )
{
io = Servent::instance()->getIODeviceForUrl( m_currentTrack );
if ( !io || io.isNull() )
{
tLog() << "Error getting iodevice for" << result->url();
err = true;
}
}
}
if ( !err )
{
tLog() << "Starting new song:" << m_currentTrack->url();
emit loading( m_currentTrack );
if ( !isHttpResult( m_currentTrack->url() ) && !isLocalResult( m_currentTrack->url() ) )
{
m_mediaObject->setCurrentSource( io.data() );
m_mediaObject->currentSource().setAutoDelete( false );
m_isPlayingHttp = false;
}
else
{
if ( !isLocalResult( m_currentTrack->url() ) )
{
QUrl furl = m_currentTrack->url();
if ( m_currentTrack->url().contains( "?" ) )
{
furl = QUrl( m_currentTrack->url().left( m_currentTrack->url().indexOf( '?' ) ) );
furl.setEncodedQuery( QString( m_currentTrack->url().mid( m_currentTrack->url().indexOf( '?' ) + 1 ) ).toLocal8Bit() );
}
m_mediaObject->setCurrentSource( furl );
}
else
{
QString furl = m_currentTrack->url();
#ifdef Q_OS_WIN32
if ( furl.startsWith( "file://" ) )
furl = furl.right( furl.length() - 7 );
#endif
m_mediaObject->setCurrentSource( furl );
}
m_mediaObject->currentSource().setAutoDelete( true );
m_isPlayingHttp = true;
}
if ( !m_input.isNull() )
{
m_input->close();
m_input.clear();
}
m_input = io;
m_mediaObject->play();
emit started( m_currentTrack );
DatabaseCommand_LogPlayback* cmd = new DatabaseCommand_LogPlayback( m_currentTrack, DatabaseCommand_LogPlayback::Started );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
Tomahawk::InfoSystem::InfoCriteriaHash trackInfo;
trackInfo["title"] = m_currentTrack->track();
trackInfo["artist"] = m_currentTrack->artist()->name();
trackInfo["album"] = m_currentTrack->album()->name();
if ( TomahawkSettings::instance()->verboseNotifications() )
sendNowPlayingNotification();
Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo(
s_aeInfoIdentifier,
Tomahawk::InfoSystem::InfoNowPlaying,
QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( trackInfo ) );
}
}
if ( err )
{
stop();
return false;
}
m_waitingOnNewTrack = false;
return true;
}
示例14: loading
bool
AudioEngine::loadTrack( const Tomahawk::result_ptr& result )
{
bool err = false;
{
QSharedPointer<QIODevice> io;
if ( result.isNull() )
err = true;
else
{
setCurrentTrack( result );
if ( !isHttpResult( m_currentTrack->url() ) && !isLocalResult( m_currentTrack->url() ) )
{
io = Servent::instance()->getIODeviceForUrl( m_currentTrack );
if ( !io || io.isNull() )
{
tLog() << "Error getting iodevice for" << result->url();
err = true;
}
}
}
if ( !err )
{
tLog() << "Starting new song:" << m_currentTrack->url();
emit loading( m_currentTrack );
if ( !isHttpResult( m_currentTrack->url() ) && !isLocalResult( m_currentTrack->url() ) )
{
if ( QNetworkReply* qnr_io = qobject_cast< QNetworkReply* >( io.data() ) )
m_mediaObject->setCurrentSource( new QNR_IODeviceStream( qnr_io, this ) );
else
m_mediaObject->setCurrentSource( io.data() );
m_mediaObject->currentSource().setAutoDelete( false );
}
else
{
if ( !isLocalResult( m_currentTrack->url() ) )
{
QUrl furl = m_currentTrack->url();
if ( m_currentTrack->url().contains( "?" ) )
{
furl = QUrl( m_currentTrack->url().left( m_currentTrack->url().indexOf( '?' ) ) );
furl.setEncodedQuery( QString( m_currentTrack->url().mid( m_currentTrack->url().indexOf( '?' ) + 1 ) ).toLocal8Bit() );
}
m_mediaObject->setCurrentSource( furl );
}
else
{
QString furl = m_currentTrack->url();
#ifdef Q_WS_WIN
if ( furl.startsWith( "file://" ) )
furl = furl.right( furl.length() - 7 );
#endif
tLog( LOGVERBOSE ) << "Passing to Phonon:" << furl << furl.toLatin1();
m_mediaObject->setCurrentSource( furl );
}
m_mediaObject->currentSource().setAutoDelete( true );
}
if ( !m_input.isNull() )
{
m_input->close();
m_input.clear();
}
m_input = io;
queueState( Playing );
emit started( m_currentTrack );
if ( TomahawkSettings::instance()->privateListeningMode() != TomahawkSettings::FullyPrivate )
{
DatabaseCommand_LogPlayback* cmd = new DatabaseCommand_LogPlayback( m_currentTrack, DatabaseCommand_LogPlayback::Started );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
}
sendNowPlayingNotification( Tomahawk::InfoSystem::InfoNowPlaying );
}
}
if ( err )
{
stop();
return false;
}
m_waitingOnNewTrack = false;
return true;
}
示例15: setEncodedQuery
void QUrlProto::setEncodedQuery(const QByteArray &query)
{
QUrl *item = qscriptvalue_cast<QUrl*>(thisObject());
if (item)
item->setEncodedQuery(query);
}