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 LibreFM::submission(QString artist, QString title, int time, QString album, int sec, QString src, QString rating, int track, QString mb) { if(sec < 30 || (QDateTime::currentDateTime().toTime_t() - time) < (sec/2)) { proxy->log(QString("sec %1").arg(QString::number(sec))); proxy->log(QString("time %1").arg(QString::number(QDateTime::currentDateTime().toTime_t() - time))); return; } if(!connected || httpPostId) { handshake(librefmUser, librefmPassword); QList<QVariant> item; item << artist; item << title; item << time; item << album; item << sec; item << src; item << rating; item << track; item << mb; stack << item; return; } if(proxy->hasVariable("proxyEnabled") && proxy->getVariable("proxyEnabled") == "true") { http.setProxy(proxy->getVariable("proxyHost"), proxy->getVariable("proxyPort").toInt(), proxy->getVariable("proxyUser"), proxy->getVariable("proxyPassword")); } QUrl u(submissionUrl); QUrl url(""); url.addQueryItem("s", session); url.addQueryItem("a[0]", artist); url.addQueryItem("t[0]", title); url.addQueryItem("i[0]", QString::number(time)); url.addQueryItem("o[0]", src); url.addQueryItem("r[0]", rating); url.addQueryItem("l[0]", QString::number(sec)); url.addQueryItem("b[0]", album); url.addQueryItem("n[0]", QString::number(track)); url.addQueryItem("m[0]", mb); QHttp::ConnectionMode mode = u.scheme().toLower() == "https" ? QHttp::ConnectionModeHttps : QHttp::ConnectionModeHttp; http.setHost(u.host(), mode, u.port(80)); QHttpRequestHeader header(QLatin1String("POST"), QString(u.toEncoded())); header.setValue(QLatin1String("Connection"), QLatin1String("Keep-Alive")); header.setValue(QLatin1String("Host"), u.host().toLatin1()); header.setContentLength(url.toString().toUtf8().remove(0,1).size()); header.setContentType(QLatin1String("application/x-www-form-urlencoded")); httpPostId = http.request(header, url.toString().toUtf8().remove(0,1)); }
QNetworkReply* ownCloudInfo::mkdirRequest( const QString& dir ) { qDebug() << "OCInfo Making dir " << dir; MirallConfigFile cfgFile( _configHandle ); QUrl url = QUrl( cfgFile.ownCloudUrl( _connection, true ) + dir ); QHttp::ConnectionMode conMode = QHttp::ConnectionModeHttp; if (url.scheme() == "https") conMode = QHttp::ConnectionModeHttps; QHttp* qhttp = new QHttp(QString(url.encodedHost()), conMode, 0, this); connect(qhttp, SIGNAL(requestStarted(int)), this,SLOT(qhttpRequestStarted(int))); connect(qhttp, SIGNAL(requestFinished(int, bool)), this,SLOT(qhttpRequestFinished(int,bool))); connect(qhttp, SIGNAL(responseHeaderReceived(QHttpResponseHeader)), this, SLOT(qhttpResponseHeaderReceived(QHttpResponseHeader))); //connect(qhttp, SIGNAL(authenticationRequired(QString,quint16,QAuthenticator*)), this, SLOT(qhttpAuthenticationRequired(QString,quint16,QAuthenticator*))); QHttpRequestHeader header("MKCOL", QString(url.encodedPath()), 1,1); /* header */ header.setValue("Host", QString(url.encodedHost())); header.setValue("User-Agent", QString("mirall-%1").arg(MIRALL_STRINGIFY(MIRALL_VERSION)).toAscii() ); header.setValue("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"); header.setValue("Accept-Language", "it,de-de;q=0.8,it-it;q=0.6,en-us;q=0.4,en;q=0.2"); header.setValue("Connection", "keep-alive"); header.setContentType("application/x-www-form-urlencoded"); //important header.setContentLength(0); QString con = _configHandle; if( con.isEmpty() ) con = DEFAULT_CONNECTION; if( _credentials.contains(con)) { oCICredentials creds = _credentials.value(con); QString concatenated = creds.user + QLatin1Char(':') + creds.passwd; const QString b(QLatin1String("Basic ")); QByteArray data = b.toLocal8Bit() + concatenated.toLocal8Bit().toBase64(); header.setValue("Authorization", data); qhttp->setUser( creds.user, creds.passwd ); } int david = qhttp->request(header,0,0); //////////////// connect(davinfo, SIGNAL(dataSendProgress(int,int)), this, SLOT(SendStatus(int, int))); /////////////////connect(davinfo, SIGNAL(done(bool)), this,SLOT(DavWake(bool))); //connect(_http, SIGNAL(requestFinished(int, bool)), this,SLOT(qhttpRequestFinished(int,bool))); ///////////connect(davinfo, SIGNAL(responseHeaderReceived(constQHttpResponseHeader &)), this, SLOT(RegisterBackHeader(constQHttpResponseHeader &))); return NULL; }
bool Harcelement::callAdd() { QByteArray content(this->buildRequest().toUtf8()); QHttpRequestHeader header("POST", this->url_api.path()); header.setValue("Host", this->url_api.host()); header.setContentType("application/x-www-form-urlencoded"); header.setContentLength(content.length()); QHttp *http = new QHttp(this->getHost()); http->request(header, content); QObject::connect(http, SIGNAL(done(bool)), this->main_window, SLOT(state(bool))); QObject::connect(http, SIGNAL(requestFinished(int,bool)), this->main_window, SLOT(httpFinished(int))); QObject::connect(http, SIGNAL(responseHeaderReceived(QHttpResponseHeader)), this->main_window, SLOT(readHeader(QHttpResponseHeader))); return true; }
void LibreFM::nowplaying(QString artist, QString title, QString album, int sec, int track, QString mb) { if(!connected || httpPostId) { handshake(librefmUser, librefmPassword); QList<QVariant> item; item << artist; item << title; item << album; item << sec; item << track; item << mb; stack << item; return; } if(proxy->hasVariable("proxyEnabled") && proxy->getVariable("proxyEnabled") == "true") { http.setProxy(proxy->getVariable("proxyHost"), proxy->getVariable("proxyPort").toInt(), proxy->getVariable("proxyUser"), proxy->getVariable("proxyPassword")); } QUrl u(nowPlayingUrl); QUrl url(""); url.addQueryItem("s", session); url.addQueryItem("a", artist); url.addQueryItem("t", title); url.addQueryItem("b", album); url.addQueryItem("l", QString::number(sec)); url.addQueryItem("n", QString::number(track)); url.addQueryItem("m", mb); QHttp::ConnectionMode mode = u.scheme().toLower() == "https" ? QHttp::ConnectionModeHttps : QHttp::ConnectionModeHttp; http.setHost(u.host(), mode, u.port(80)); QHttpRequestHeader header(QLatin1String("POST"), QString(u.toEncoded())); header.setValue(QLatin1String("Connection"), QLatin1String("Keep-Alive")); header.setValue(QLatin1String("Host"), u.host().toLatin1()); header.setContentLength(url.toString().toUtf8().remove(0,1).size()); header.setContentType(QLatin1String("application/x-www-form-urlencoded")); httpPostId = http.request(header, url.toString().toUtf8().remove(0,1)); }
bool Harcelement::callDelete() { if (this->hash.isEmpty()) { return false; } QByteArray content(""); QHttpRequestHeader header("DELETE", this->url_api.path() + QString("?%1").arg(QString(QUrl::toPercentEncoding(this->hash))).toUtf8()); header.setValue("Host", this->url_api.host()); header.setContentType("application/x-www-form-urlencoded"); header.setContentLength(content.length()); QHttp *http = new QHttp(this->getHost()); http->request(header, content); QObject::connect(http, SIGNAL(done(bool)), this->main_window, SLOT(state(bool))); QObject::connect(http, SIGNAL(requestFinished(int,bool)), this->main_window, SLOT(httpFinished(int))); QObject::connect(http, SIGNAL(responseHeaderReceived(QHttpResponseHeader)), this->main_window, SLOT(readHeader(QHttpResponseHeader))); return true; }
void ownCloudInfo::mkdirRequest( const QString& dir ) { qDebug() << "OCInfo Making dir " << dir; MirallConfigFile cfgFile( _configHandle ); QUrl url = QUrl( cfgFile.ownCloudUrl( _connection, true ) + dir ); QHttp::ConnectionMode conMode = QHttp::ConnectionModeHttp; if (url.scheme() == "https") conMode = QHttp::ConnectionModeHttps; QHttp* qhttp = new QHttp(url.host(), conMode, 0, this); qhttp->setUser( cfgFile.ownCloudUser( _connection ), cfgFile.ownCloudPasswd( _connection )); connect(qhttp, SIGNAL(requestStarted(int)), this,SLOT(qhttpRequestStarted(int))); connect(qhttp, SIGNAL(requestFinished(int, bool)), this,SLOT(qhttpRequestFinished(int,bool))); connect(qhttp, SIGNAL(responseHeaderReceived(QHttpResponseHeader)), this, SLOT(qhttpResponseHeaderReceived(QHttpResponseHeader))); //connect(qhttp, SIGNAL(authenticationRequired(QString,quint16,QAuthenticator*)), this, SLOT(qhttpAuthenticationRequired(QString,quint16,QAuthenticator*))); QHttpRequestHeader header("MKCOL", url.path(), 1,1); /* header */ header.setValue("Host", url.host() ); header.setValue("User-Agent", QString("mirall-%1").arg(MIRALL_STRINGIFY(MIRALL_VERSION)).toAscii() ); header.setValue("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"); header.setValue("Accept-Language", "it,de-de;q=0.8,it-it;q=0.6,en-us;q=0.4,en;q=0.2"); header.setValue("Connection", "keep-alive"); header.setContentType("application/x-www-form-urlencoded"); //important header.setContentLength(0); header.setValue("Authorization", cfgFile.basicAuthHeader()); int david = qhttp->request(header,0,0); //////////////// connect(davinfo, SIGNAL(dataSendProgress(int,int)), this, SLOT(SendStatus(int, int))); /////////////////connect(davinfo, SIGNAL(done(bool)), this,SLOT(DavWake(bool))); //connect(_http, SIGNAL(requestFinished(int, bool)), this,SLOT(qhttpRequestFinished(int,bool))); ///////////connect(davinfo, SIGNAL(responseHeaderReceived(constQHttpResponseHeader &)), this, SLOT(RegisterBackHeader(constQHttpResponseHeader &))); }