void Pastebin::postPaste(const QByteArray& data, Language lang, const QString& title, const QString& expire, quint32 vis) { QUrl requestUrl(PASTEBIN_URL + PASTEBIN_POST); QUrl requestArgs; QNetworkRequest request(requestUrl); QString langOpt = "text"; if (lang != PlainText) langOpt = languageString(lang); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); requestArgs.addEncodedQueryItem("api_dev_key", m_developerKey.toUtf8()); requestArgs.addEncodedQueryItem("api_option", "paste"); requestArgs.addEncodedQueryItem("api_paste_expire_date", expire.toUtf8()); requestArgs.addEncodedQueryItem("api_paste_private", QString("%1").arg(vis).toUtf8()); requestArgs.addEncodedQueryItem("api_paste_format", langOpt.toUtf8()); requestArgs.addEncodedQueryItem("api_paste_code", QUrl::toPercentEncoding(QString(data).toAscii())); if (!title.isEmpty()) requestArgs.addEncodedQueryItem("api_paste_name", QUrl::toPercentEncoding(title.toAscii())); if (!m_userKey.isEmpty()) requestArgs.addEncodedQueryItem("api_user_key", m_userKey.toUtf8()); m_networkAccess->post(request, requestArgs.encodedQuery()); }
void SeafileApiRequest::send() { if (token_.size() > 0) { api_client_->setToken(token_); } switch (method_) { case METHOD_GET: url_.setQueryItems(params_); api_client_->get(url_); break; case METHOD_POST: QUrl params; for (int i = 0; i < params_.size(); i++) { QPair<QString, QString> pair = params_[i]; params.addEncodedQueryItem(QUrl::toPercentEncoding(pair.first), QUrl::toPercentEncoding(pair.second)); } api_client_->post(url_, params.encodedQuery()); break; } connect(api_client_, SIGNAL(requestSuccess(QNetworkReply&)), this, SLOT(requestSuccess(QNetworkReply&))); connect(api_client_, SIGNAL(networkError(const QNetworkReply::NetworkError&, const QString&)), this, SIGNAL(networkError(const QNetworkReply::NetworkError&, const QString&))); connect(api_client_, SIGNAL(requestFailed(int)), this, SIGNAL(failed(int))); connect(api_client_, SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError>&)), this, SLOT(onSslErrors(QNetworkReply*, const QList<QSslError>&))); }
void SohuMiniBlog::postPairs(const QString& aUrl, const QString& aKey1, const QString& aValue1, const QString& aKey2, const QString& aValue2) { qDebug() << "SohuMiniBlog:postPairs" << aUrl << aKey1 << aValue1 << aKey2 << aValue2; qDebug() << aUrl; if(aUrl.isEmpty()) { return; } mRequest->setUrl(QUrl(aUrl)); QByteArray data; QUrl params; params.addQueryItem(aKey1, aValue1);//addQueryItem params.addQueryItem(aKey2, aValue2);//addQueryItem data = params.encodedQuery(); if(NULL != gUniqueNetwrkManager) { mRequestTimeoutTimer->setInterval(KRequestTimeOut); mRequestTimeoutTimer->start(); mReply = gUniqueNetwrkManager->post(*mRequest, data); connect(mReply, SIGNAL(finished()), this, SLOT(onReplyFinished())); } }
void SearchController::search(const QString &search, const QString &author, const QString &hashKey, int searchType, int categoryType, int searchIn, int numberOfMessages, int sortBy) { const QUrl url(DefineConsts::FORUM_URL + "/search.php?config=hfr.inc"); QNetworkRequest request(url); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); QUrl params; params.addQueryItem("hash_check", hashKey); params.addQueryItem("cat", QString::number(categoryType)); params.addQueryItem("titre", QString::number(searchIn)); params.addQueryItem("search", search); params.addQueryItem("searchtype", QString::number(searchType)); params.addQueryItem("pseud", author); params.addQueryItem("resSearch", QString::number(numberOfMessages)); params.addQueryItem("orderSearch", QString::number(sortBy)); QNetworkReply* reply = HFRNetworkAccessManager::get()->post(request, params.encodedQuery()); bool ok = connect(reply, SIGNAL(finished()), this, SLOT(checkReply())); Q_ASSERT(ok); Q_UNUSED(ok); }
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(); }
QByteArray QUrlProto::encodedQuery() const { QUrl *item = qscriptvalue_cast<QUrl*>(thisObject()); if (item) return item->encodedQuery(); return QByteArray(); }
void Snap2ChatAPISimple::request(QVariant params) { QUrl dataToSend; QVariantMap paramsMap = params.toMap(); const QString endpoint = paramsMap.value("endpoint").toString(); if(endpoint == "listen") { dataToSend.addQueryItem("userid", paramsMap.value("userid").toString()); } else if(endpoint == "login" || endpoint == "register") { dataToSend.addQueryItem("username", paramsMap.value("username").toString()); dataToSend.addQueryItem("password", paramsMap.value("password").toString()); } QNetworkRequest request; request.setUrl(QUrl(PROTOCOL + API_ENDPOINT + endpoint + ".php")); request.setHeader(QNetworkRequest::ContentTypeHeader, CONTENT_TYPE); QNetworkReply* reply = m_manager.post(request, dataToSend.encodedQuery()); reply->setProperty("endpoint", endpoint); connect (reply, SIGNAL(finished()), this, SLOT(onComplete())); }
void STULogin::login(const QString &user, const QString &passwd){ // qDebug() << "now login " + user + "\t" + passwd; logining = true; // QtNetWorkAccessManager works asynchronously this->user_copy = user; // qDebug() << this->user; this->passwd = passwd; // record the user info for try again untill MAX_COUNT or login if (is_connected){ wrongCount = 0; return; } requestAddr->setUrl(LOGIN_REQUEST_ADDR); QUrl params; params.addQueryItem(USERNAME_INPUT,user); params.addQueryItem(PASSWD_INPUT,passwd); params.addQueryItem(LOGIN_INPUT,""); QByteArray postData = params.encodedQuery(); QNetworkRequest request(*requestAddr); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); delayForSomeTime(600); QNetworkReply *reply = syncHttpPost(request, postData); handleReply(reply); processStates(replyData); emit stateChanged(is_connected,user,used,total,left); //qDebug() << replyData; }
int Url::encodedQuery ( lua_State * L )// const : QByteArray { QUrl* lhs = ValueInstaller2<QUrl>::check( L, 1 ); //QByteArray* res = ValueInstaller2<QByteArray>::create( L ); Util::push( L, lhs->encodedQuery().data() ); return 1; }
bool ActivatePage::checkUserActivated(int user_id) { serverQueryFinished = false; serverQueryError = false; label_message->setText("Logging in..."); QString url( "https://screencloud.net/1.0/users/check_activated.xml"); QString token, tokenSecret; // create a request parameters map QUrl bodyParams; bodyParams.addQueryItem("user_id", QString::number(user_id)); bodyParams.addQueryItem("oauth_version", "1.0"); bodyParams.addQueryItem("oauth_signature_method", "PLAINTEXT"); bodyParams.addQueryItem("oauth_consumer_key", CONSUMER_KEY_SCREENCLOUD); bodyParams.addQueryItem("oauth_signature", CONSUMER_SECRET_SCREENCLOUD); QByteArray body = bodyParams.encodedQuery(); QNetworkRequest request; request.setUrl(QUrl(url)); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); manager->post(request, body); return true; }
void Pastebin::submitPaste(const QString& pasteContent, const QString& pasteTitle, const QString& format, const QString& expiration, const PasteListing::Visibility visibility) { qDebug() << "submitPaste()"; QNetworkRequest request(buildUrl("http://pastebin.com/api/api_post.php")); request.setHeader(QNetworkRequest::ContentTypeHeader, URLENCODED_CONTENT_TYPE); QUrl params; params.addQueryItem("api_dev_key", PASTEBIN_DEV_KEY); params.addQueryItem("api_user_key", apiKey()); params.addQueryItem("api_option", "paste"); params.addQueryItem("api_paste_code", pasteContent); params.addQueryItem("api_paste_private", QString("%1").arg(static_cast<int>(visibility))); if(!pasteTitle.isEmpty()) { params.addQueryItem("api_paste_name", pasteTitle); } if(!expiration.isEmpty()) { params.addQueryItem("api_paste_expire_date", expiration); } if(!format.isEmpty()) { params.addQueryItem("api_paste_format", format); } QNetworkReply *reply = accessManager_.post(request, params.encodedQuery()); connect(reply, SIGNAL(finished()), this, SLOT(onSubmitPasteFinished())); }
void PreferencesDialog::on_button_logout_clicked() { QMessageBox msgBox; msgBox.addButton(QMessageBox::Yes); msgBox.addButton(QMessageBox::No); msgBox.setText("Are you sure that you want to log out? This will remove the saved account details and quit the application."); msgBox.setIcon(QMessageBox::Information); int selection = msgBox.exec(); if(selection == QMessageBox::Yes) { //Send logout request QUrl url( "https://api.screencloud.net/1.0/users/logout.xml" ); // construct the parameters string url.addQueryItem("oauth_version", "1.0"); url.addQueryItem("oauth_signature_method", "PLAINTEXT"); url.addQueryItem("oauth_token", token); url.addQueryItem("oauth_consumer_key", CONSUMER_KEY_SCREENCLOUD); url.addQueryItem("oauth_signature", CONSUMER_SECRET_SCREENCLOUD + QString("&") + tokenSecret); url.addQueryItem("oauth_timestamp", QString::number(QDateTime::currentDateTimeUtc().toTime_t())); url.addQueryItem("oauth_nonce", NetworkUtils::generateNonce(15)); QUrl bodyParams; bodyParams.addQueryItem("token", token); QByteArray body = bodyParams.encodedQuery(); QNetworkRequest request; request.setUrl(url); manager->post(request, body); userHasLoggedOut = true; } }
void AJAXChat::connectToServer(const QString &server, const QString &userName, const QString &password, const QString &channel, const QString &forumLoginUrl) { _server = server; // setup request parameters QUrl params; params.addQueryItem("login", "login"); params.addQueryItem("redirect", server); params.addQueryItem("username", userName); params.addQueryItem("password", password); params.addQueryItem("channelName", channel); params.addQueryItem("lang", "en"); params.addQueryItem("submit", "Login"); // if the forum login url is set, then login to the forum and then go to the chat, // otherwise, directly go to the chat QString connectUrl = forumLoginUrl.isEmpty() ? server : forumLoginUrl; QUrl url(connectUrl); QNetworkRequest request(url); // content type is needed or you will get runtime debug warnings. This kind of header is needed or // the chat will just asks the bot to logout request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); QNetworkReply *reply = net->post(request, params.encodedQuery()); connect(reply, SIGNAL(finished()), this, SLOT(connectFinished())); connect(reply, SIGNAL(finished()), reply, SLOT(deleteLater())); }
void PrivateMessageController::deletePrivateMessage(const QString &urlFirstPage) { QRegExp catIDRegExp("cat=([0-9prive]+)"); if(catIDRegExp.indexIn(urlFirstPage) == -1) return; const QUrl url(DefineConsts::FORUM_URL + "/modo/manageaction.php?config=hfr.inc&cat=" + catIDRegExp.cap(1) + "&type_page=forum1&moderation=0"); QRegExp postIDRegExp("post=([0-9]+)"); if(postIDRegExp.indexIn(urlFirstPage) == -1) return; QNetworkRequest request(url); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); QUrl params; params.addQueryItem("action_reaction", "valid_eff_prive"); params.addQueryItem("topic1", postIDRegExp.cap(1)); params.addQueryItem("hash_check", m_HashCheck); QNetworkReply* reply = HFRNetworkAccessManager::get()->post(request, params.encodedQuery()); bool ok = connect(reply, SIGNAL(finished()), this, SLOT(checkMessageDeleted())); Q_ASSERT(ok); Q_UNUSED(ok); }
//! HTTP POST request void GoogleReader::sendHttpPost(QUrl url, QUrl params) { QNetworkRequest request(url); request.setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded"); request.setRawHeader("Authorization", QString("GoogleLogin auth=%1").arg(auth_).toUtf8()); managerHttpPost_.post(request, params.encodedQuery()); }
void MainWindow::login(bool timer) { supressMessage = timer; if(ui->remember->isChecked()){ QSettings setting("daiict","cyberoam_autoLogin"); setting.setValue("uname",ui->user_field->text()); setting.setValue("pass",ui->pass_field->text()); setting.sync(); } else { QSettings setting("daiict","cyberoam_autoLogin"); setting.clear(); } if(traymode){ if(ui->user_field->text() == "" || ui->pass_field->text() == ""){ this->show(); tray->showMessage("Cannot Login","Incomplete credentials provided"); showDialog(); return; } } if(isLoggedin && !timer){ QUrl credentials; credentials.addQueryItem("mode","193"); credentials.addQueryItem("username",ui->user_field->text()); req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); gotReply = false; manager->post(req,credentials.encodedQuery()); timeout.start(); } else { QUrl credentials; credentials.addQueryItem("mode","191"); credentials.addQueryItem("username",ui->user_field->text()); credentials.addQueryItem("password",ui->pass_field->text()); req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); gotReply = false; manager->post(req,credentials.encodedQuery()); timeout.start(); tm.stop(); tm.start(); } }
void Pastebin::requestTrending() { QNetworkRequest request(buildUrl("http://pastebin.com/api/api_post.php")); request.setHeader(QNetworkRequest::ContentTypeHeader, URLENCODED_CONTENT_TYPE); QUrl params; params.addQueryItem("api_dev_key", PASTEBIN_DEV_KEY); params.addQueryItem("api_option", "trends"); QNetworkReply *reply = accessManager_.post(request, params.encodedQuery()); connect(reply, SIGNAL(finished()), this, SLOT(onTrendingFinished())); }
QNetworkReply* NetBalanceGetter::post_req(){ QUrl url = QUrl(QString("http://cabinet.telecom.mipt.ru/")); QUrl data; data.addQueryItem("login", QString::number(account)); data.addQueryItem("password",password); QNetworkRequest request(url); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); return manager->post(request, data.encodedQuery()); }
bool ActivatePage::getAccessToken() { serverQueryFinished = false; serverQueryError = false; disconnect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*))); label_message->setText("Requesting key..."); QUrl url( "https://screencloud.net/1.0/oauth/access_token_xauth" ); // create a request parameters map QUrl bodyParams; bodyParams.addQueryItem( "data[User][email]", field("register.email").toString()); bodyParams.addQueryItem( "data[User][password]", field("register.password").toString()); bodyParams.addQueryItem("oauth_version", "1.0"); bodyParams.addQueryItem("oauth_signature_method", "PLAINTEXT"); bodyParams.addQueryItem("oauth_consumer_key", CONSUMER_KEY_SCREENCLOUD); bodyParams.addQueryItem("oauth_signature", CONSUMER_SECRET_SCREENCLOUD); bodyParams.addQueryItem("oauth_timestamp", QString::number(QDateTime::currentDateTimeUtc().toTime_t())); bodyParams.addQueryItem("oauth_nonce", NetworkUtils::generateNonce(15)); QByteArray body = bodyParams.encodedQuery(); QNetworkRequest request; request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); request.setUrl(url); QNetworkReply* reply = manager->post(request, body); QEventLoop loop; connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*))); if ( reply->error() == QNetworkReply::NoError ) { //Save to qsettings QString replyText = reply->readAll(); if(replyText.isEmpty()) { label_message->setText("<font color='red'>Failed to get credentials. Empty reply from server.</font>"); return false; } INFO(reply->request().url().toString() + " returned: " + replyText); QUrl replyParams = QUrl("?" + replyText); QSettings settings("screencloud", "ScreenCloud"); settings.beginGroup("account"); settings.setValue("token", replyParams.queryItemValue("oauth_token")); settings.setValue("token-secret", replyParams.queryItemValue("oauth_token_secret")); settings.setValue("email", field("register.email").toString()); settings.setValue("logged-in", true); settings.endGroup(); return true; }else { label_message->setText("<font color='red'>OAuth error</font>"); return false; } return false; }
void Pastebin::login(const QString& username, const QString& password) { QNetworkRequest request(buildUrl("http://pastebin.com/api/api_login.php")); request.setHeader(QNetworkRequest::ContentTypeHeader, URLENCODED_CONTENT_TYPE); QUrl params; params.addQueryItem("api_dev_key", PASTEBIN_DEV_KEY); params.addQueryItem("api_user_name", username.toUtf8()); params.addQueryItem("api_user_password", password.toUtf8()); QNetworkReply *reply = accessManager_.post(request, params.encodedQuery()); connect(reply, SIGNAL(finished()), this, SLOT(onLoginFinished())); }
void DeckStatsInterface::analyzeDeck(DeckList *deck) { QUrl params; params.addQueryItem("deck", deck->writeToString_Plain()); QByteArray data; data.append(params.encodedQuery()); QNetworkRequest request(QUrl("http://deckstats.net/index.php")); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); manager->post(request, data); }
void Pastebin::trendingPastes() { QUrl requestUrl(PASTEBIN_URL + PASTEBIN_POST); QUrl requestArgs; QNetworkRequest request(requestUrl); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); requestArgs.addEncodedQueryItem("api_dev_key", m_developerKey.toUtf8()); requestArgs.addEncodedQueryItem("api_option", "trends"); m_networkAccess->post(request, requestArgs.encodedQuery()); }
bool HttpJob::execute(int state, QNetworkAccessManager *manager) { switch (state) { case Init: case Portal: { QNetworkRequest request(m_portalUrl); QNetworkReply *reply = manager->get(request); if (reply->error() != QNetworkReply::NoError) setErrorAndEmitFinished(SomethingWentWrong, reply->errorString()); } return true; case Login: { QUrl data; data.addQueryItem("j_username", m_username); data.addQueryItem("j_password", m_password); QNetworkRequest request(m_loginUrl); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); request.setHeader(QNetworkRequest::ContentLengthHeader, data.encodedQuery().size()); QNetworkReply *reply = manager->post(request, data.encodedQuery()); if (reply->error() != QNetworkReply::NoError) setErrorAndEmitFinished(SomethingWentWrong, reply->errorString()); } return true; default: break; } return false; }
void Pastebin::login() { QUrl requestUrl(PASTEBIN_URL + PASTEBIN_LOGIN); QUrl requestArgs; QNetworkRequest request(requestUrl); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); requestArgs.addEncodedQueryItem("api_dev_key", m_developerKey.toUtf8()); requestArgs.addEncodedQueryItem("api_user_name", QUrl::toPercentEncoding(m_userName)); requestArgs.addEncodedQueryItem("api_user_password", QUrl::toPercentEncoding(m_password)); m_networkAccess->post(request, requestArgs.encodedQuery()); }
bool GoogleTranslate::translate(const Language &from, const Language &to, const QString &text) { #if QT_VERSION < QT_VERSION_CHECK(5,0,0) QUrl query("https://translate.googleapis.com/translate_a/single"); QUrl dataQuery; #else QUrl url("https://translate.googleapis.com/translate_a/single"); QUrlQuery query, dataQuery; #endif query.addQueryItem("client", "gtx"); query.addQueryItem("hl", "en"); query.addQueryItem("sl", from.info.toString()); query.addQueryItem("tl", to.info.toString()); query.addQueryItem("ie", "UTF-8"); query.addQueryItem("oe", "UTF-8"); // `dt` specifies what to return in the response query.addQueryItem("dt", "t"); // Translation // query.addQueryItem("dt", "at"); // Alternate translations query.addQueryItem("dt", "bd"); // Dictionary (with reverse translations and articles) query.addQueryItem("dt", "rm"); // Transliteration // query.addQueryItem("dt", "md"); // Definitions of source word // query.addQueryItem("dt", "ss"); // Source text synonyms // query.addQueryItem("dt", "ex"); // Examples // query.addQueryItem("dt", "rw"); // "See also" list // query.addQueryItem("dt", "ld"); // Unknown // query.addQueryItem("dt", "qca"); // Unknown // query.addQueryItem("ssel", "3"); // query.addQueryItem("tsel", "0"); // query.addQueryItem("otf", "1"); // query.addQueryItem("tk", generateToken(text)); dataQuery.addQueryItem("q", text); #if QT_VERSION < QT_VERSION_CHECK(5,0,0) QNetworkRequest request(query); const QByteArray data(dataQuery.encodedQuery()); #else url.setQuery(query); QNetworkRequest request(url); const QByteArray data(dataQuery.toString(QUrl::FullyEncoded).toUtf8()); #endif request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded;charset=UTF-8"); request.setRawHeader("User-Agent", "Mozilla/5.0"); request.setRawHeader("Referer", "https://translate.google.com/"); request.setSslConfiguration(m_sslConfiguration); m_reply = m_nam.post(request, data); return true; }
HttpEngine::HttpEngine(QUrl url, QUrl referrer, QUuid proxyUuid) : m_pRemote(0), m_url(url) { QString user_info; QString query, host; // QList<Proxy> listProxy = Proxy::loadProxys(); m_proxyData.nType = Proxy::ProxyNone; host = url.host(); if(url.port(80) != 80) host += QString(":") + QString::number(url.port(80)); if (Proxy::isProxyEnabled()){ Proxy p = Proxy:: loadProxy(); if(p.uuid == proxyUuid) { m_proxyData = p; } } if(!url.hasQuery()) query = url.path(); else query = url.path()+"?"+url.encodedQuery(); if(query.isEmpty()) query = "/"; if(m_proxyData.nType == Proxy::ProxyHttp) { m_header.setRequest("GET", QString("%1://%2%3").arg(url.scheme()).arg(host).arg(query)); if(!m_proxyData.strUser.isEmpty()) m_header.addValue("Proxy-Authorization", QString("Basic %1").arg((QString) (m_proxyData.strUser+":"+m_proxyData.strPassword).toUtf8().toBase64()) ); } else m_header.setRequest("GET", query); user_info = url.userInfo(); if(!user_info.isEmpty()) m_header.addValue("Authorization", QString("Basic %1").arg( QString(user_info.toUtf8().toBase64()) )); if(referrer.isValid()) m_header.addValue("Referrer", referrer.toString()); m_header.addValue("Host", host); m_header.addValue("Connection", "close"); }
void HttpPoll::connectToHost(const QString &proxyHost, int proxyPort, const QUrl &url) { resetConnection(true); bool useSsl = false; d->port = 80; // using proxy? if(!proxyHost.isEmpty()) { d->host = proxyHost; d->port = proxyPort; d->url = url; d->use_proxy = true; } else { d->host = url.host(); if(url.port() != -1) d->port = url.port(); else if (url.scheme() == "https") { d->port = 443; useSsl = true; } #if QT_VERSION < 0x050000 d->url = url.path() + "?" + url.encodedQuery(); #else d->url.setUrl(url.path() + "?" + url.query(QUrl::FullyEncoded), QUrl::StrictMode); #endif d->use_proxy = false; } resetKey(); bool last; QString key = getKey(&last); #ifdef PROX_DEBUG fprintf(stderr, "HttpPoll: Connecting to %s:%d [%s]", d->host.latin1(), d->port, d->url.latin1()); if(d->user.isEmpty()) fprintf(stderr, "\n"); else fprintf(stderr, ", auth {%s,%s}\n", d->user.latin1(), d->pass.latin1()); #endif QPointer<QObject> self = this; syncStarted(); if(!self) return; d->state = 1; d->http.setUseSsl(useSsl); d->http.setAuth(d->user, d->pass); d->http.post(d->host, d->port, d->url, makePacket("0", key, "", QByteArray()), d->use_proxy); }
void GoogleSession::login(const QString &login, const QString &passwd) { if (m_state!=Invalid) { emit error(InvalidState, ""); return; } if (!http) { http = new QHttp(this); connect(http, SIGNAL(requestFinished(int, bool)), SLOT(httpResult(int, bool))); } QHttpRequestHeader header("POST", "https://www.google.com/accounts/ClientLogin"); http->setHost("google.com"); //header.setValue("Host", "google.com"); header.setValue( "User-Agent", USER_AGENT); header.setContentType("application/x-www-form-urlencoded"); QUrl query; query.addQueryItem("accountType", "HOSTED_OR_GOOGLE"); query.addQueryItem("service", "cp"); query.addQueryItem("source", GQSYNC_SOURCE); query.addQueryItem("Email", login); query.addQueryItem("Passwd", passwd); qDebug() << "Auth request"; qDebug() << "--Header"; qDebug() << header.toString(); qDebug() << "--Body"; qDebug() << query.encodedQuery(); authReqId = http->request(header, query.encodedQuery()); setState(Authenticating); }
bool CetonStreamHandler::HttpRequest( const QString &method, const QString &script, const QUrl ¶ms, QString &response, uint &status_code) const { QHttp http; http.setHost(_ip_address); QByteArray request_params(params.encodedQuery()); if (method == "GET") { QString path = script + "?" + QString(request_params); QHttpRequestHeader header(method, path); header.setValue("Host", _ip_address); http.request(header); } else { QHttpRequestHeader header(method, script); header.setValue("Host", _ip_address); header.setContentType("application/x-www-form-urlencoded"); http.request(header, request_params); } while (http.hasPendingRequests() || http.currentId()) { usleep(5000); qApp->processEvents(); } if (http.error() != QHttp::NoError) { status_code = 0; response = http.errorString(); return false; } QHttpResponseHeader resp_header = http.lastResponse(); if (!resp_header.isValid()) { status_code = 0; response = "Completed but response object was not valid"; return false; } status_code = resp_header.statusCode(); response = QString(http.readAll()); return true; }
void GoogleConnectController::renewToken() { QNetworkRequest request(QUrl("https://accounts.google.com/o/oauth2/token")); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); QUrl params; params.addQueryItem("client_id", m_Settings->value("Client_ID").value<QString>()); params.addQueryItem("client_secret", m_Settings->value("ClientSecret").value<QString>()); params.addQueryItem("refresh_token", m_Settings->value("refresh_token").value<QString>()); params.addQueryItem("grant_type", "refresh_token"); QNetworkReply* reply = HFRNetworkAccessManager::get()->post(request, params.encodedQuery()); bool ok = connect(reply, SIGNAL(finished()), this, SLOT(checkRefresh())); Q_ASSERT(ok); Q_UNUSED(ok); }