Momergil
25th December 2012, 16:54
Hello!
I want to create a http connection to a webserver and start downloading data in a QThread, but I'm having some problems.
First, my code is returning usually nothing from my searches:
HTTPClass::HTTPClass(QObject *parent) :
QObject(parent)
{
namConnection = new QNetworkAccessManager(this);
connect(namConnection, SIGNAL(finished(QNetworkReply*)),
this, SLOT(slotReplyFinished(QNetworkReply*)));
connect(namConnection, SIGNAL(authenticationRequired(QNetworkReply*,QAuth enticator*)),
this, SLOT(slotAuthenticationRequired(QNetworkReply*,QAu thenticator*)));
connect(namConnection, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,Q Authenticator*)),
this, SLOT(slotProxyAuthenticationRequired(QNetworkProxy ,QAuthenticator*)));
connect(namConnection, SIGNAL(networkSessionConnected()),
this, SLOT(slotNetworkSessionConnected()));
QNetworkRequest request;
request.setUrl(QUrl("http://en.wikipedia.org/wiki/Main_Page"));
reply = namConnection->get(request);
connect(reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
this, SLOT(slotError(QNetworkReply::NetworkError)));
connect(reply, SIGNAL(sslErrors(QList<QSslError>)),
this, SLOT(slotSslErrors(QList<QSslError>)));
}
void HTTPClass::setConnectionData()
{
}
void HTTPClass::slotReplyFinished(QNetworkReply *reply)
{
qDebug() << reply->readAll();
reply->deleteLater();
}
void HTTPClass::slotAuthenticationRequired(QNetworkRepl y *reply, QAuthenticator *aut)
{
qDebug() << "Ha";
//aut->setUser("Username");
//aut->setPassword("Password");
}
void HTTPClass::slotProxyAuthenticationRequired(QNetwor kProxy proxy, QAuthenticator *aut)
{
}
void HTTPClass::slotNetworkSessionConnected()
{
qDebug() << "Connected";
}
void HTTPClass::slotReadyRead()
{
reply->readAll();
}
void HTTPClass::slotError(QNetworkReply::NetworkError error)
{
qDebug() << QString::number(error);
}
void HTTPClass::slotSslErrors(QList<QSslError> errors)
{
qDebug() << errors[0].errorString();
}
Everything I get is 3 blanck answers. ("" "" "") What am I doing wrong? I know how to download a file from the web, but not how to read data from a url.
--
My second question: actually I don't know how the information is in the link I actually want to connect with. It must be some kind of server, but not if its an sql server with MySQL or FTP something else. How could I know how the information is stored in the link I want to connect with? (which by the way: sharkbuss.banifinvest.com.br , gate 80, parameter: /BI3S2/get.aspx)
--
My third question: in order to connect myself with this link, I now I'll have to give a password and username. Where exactly in my code should I put this part?
Thanks,
Momergil
I want to create a http connection to a webserver and start downloading data in a QThread, but I'm having some problems.
First, my code is returning usually nothing from my searches:
HTTPClass::HTTPClass(QObject *parent) :
QObject(parent)
{
namConnection = new QNetworkAccessManager(this);
connect(namConnection, SIGNAL(finished(QNetworkReply*)),
this, SLOT(slotReplyFinished(QNetworkReply*)));
connect(namConnection, SIGNAL(authenticationRequired(QNetworkReply*,QAuth enticator*)),
this, SLOT(slotAuthenticationRequired(QNetworkReply*,QAu thenticator*)));
connect(namConnection, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,Q Authenticator*)),
this, SLOT(slotProxyAuthenticationRequired(QNetworkProxy ,QAuthenticator*)));
connect(namConnection, SIGNAL(networkSessionConnected()),
this, SLOT(slotNetworkSessionConnected()));
QNetworkRequest request;
request.setUrl(QUrl("http://en.wikipedia.org/wiki/Main_Page"));
reply = namConnection->get(request);
connect(reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
this, SLOT(slotError(QNetworkReply::NetworkError)));
connect(reply, SIGNAL(sslErrors(QList<QSslError>)),
this, SLOT(slotSslErrors(QList<QSslError>)));
}
void HTTPClass::setConnectionData()
{
}
void HTTPClass::slotReplyFinished(QNetworkReply *reply)
{
qDebug() << reply->readAll();
reply->deleteLater();
}
void HTTPClass::slotAuthenticationRequired(QNetworkRepl y *reply, QAuthenticator *aut)
{
qDebug() << "Ha";
//aut->setUser("Username");
//aut->setPassword("Password");
}
void HTTPClass::slotProxyAuthenticationRequired(QNetwor kProxy proxy, QAuthenticator *aut)
{
}
void HTTPClass::slotNetworkSessionConnected()
{
qDebug() << "Connected";
}
void HTTPClass::slotReadyRead()
{
reply->readAll();
}
void HTTPClass::slotError(QNetworkReply::NetworkError error)
{
qDebug() << QString::number(error);
}
void HTTPClass::slotSslErrors(QList<QSslError> errors)
{
qDebug() << errors[0].errorString();
}
Everything I get is 3 blanck answers. ("" "" "") What am I doing wrong? I know how to download a file from the web, but not how to read data from a url.
--
My second question: actually I don't know how the information is in the link I actually want to connect with. It must be some kind of server, but not if its an sql server with MySQL or FTP something else. How could I know how the information is stored in the link I want to connect with? (which by the way: sharkbuss.banifinvest.com.br , gate 80, parameter: /BI3S2/get.aspx)
--
My third question: in order to connect myself with this link, I now I'll have to give a password and username. Where exactly in my code should I put this part?
Thanks,
Momergil