For help!why QHttp,QNetworkProxy set proxy with username and password failed?
Hi everyone:
I dont know why when I set the proxy's username and password,then I test the link,it return failed,but when without username and password,and the proxy is worked,I was fighting with the problem for sometime,but not resolve it yet.My Qt version is 4.5.2.
here is the reference code.can someone give me some suggestions or solus?
//begin mod
QNetworkProxy proxy;
proxy.setType(QNetworkProxy::HttpProxy);
proxy.setHostName(pProxyInfo->qstrProxyServerName);
proxy.setPort(pProxyInfo->qstrProxyPort.toInt());
proxy.setUser(pProxyInfo->qstrProxyUserName);
proxy.setPassword(pProxyInfo->qstrProxyPassWord);
//QNetworkProxy::setApplicationProxy(proxy);*/
m_pTestHttpObj->setProxy(proxy);
Thx and BR
Re: For help!why QHttp,QNetworkProxy set proxy with username and password failed?
http://doc.trolltech.com/4.5/qhttp.h...cationRequired
If that does not work either, you need to port your code to QNetworkAccessManager. QHttp is deprecated for Qt 4.6 which comes out in the next weeks.
Re: For help!why QHttp,QNetworkProxy set proxy with username and password failed?
thx,In fact,I had tested it with QNetworkAccessManager before,
1,first,the proxy link says ok,but ,the key is that ,when you analyse the messages sending and receiving,you will find that ,it derectly connect to server and not via proxy pc,
2,second,when QNetworkAccessManager is adapted,and the other operation eg:checking,downloading all failed.
I'am despaired almost...
here is the code with QNetworkAccessManager
//begin mod
QNetworkProxy proxy;
proxy.setType(QNetworkProxy::HttpProxy);
/*proxy.setType(QNetworkProxy::Socks5Proxy);*/
proxy.setHostName(pProxyInfo->qstrProxyServerName);
proxy.setPort(pProxyInfo->qstrProxyPort.toInt());
proxy.setUser(pProxyInfo->qstrProxyUserName);
proxy.setPassword(pProxyInfo->qstrProxyPassWord);
//QNetworkProxy::setApplicationProxy(proxy);*/
m_pTestHttpObj->setProxy(proxy);
/* QNetworkAccessManager a;
a.setProxy(proxy);*/
Re: For help!why QHttp,QNetworkProxy set proxy with username and password failed?
Even for QNetworkAccessManager, you should take a look at this signal:
http://doc.trolltech.com/4.5/qnetwor...cationRequired
Re: For help!why QHttp,QNetworkProxy set proxy with username and password failed?
Hi mgoetz:
I read the article you remended,then I tried ,but still failed,I dont know why,here is the codes,can you kindly give me some suggestions or solutions for proxy(password + username) writted with QNetworkAccessManager?
Thx a lot!
here is the code:
[
QNetworkAccessManager* qnam = new QNetworkAccessManager(this);
connect(qnam, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)), this,
SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)));
QNetworkProxy proxy;
proxy.setType(QNetworkProxy::HttpProxy);
proxy.setHostName(pProxyInfo->qstrProxyServerName);
proxy.setPort(pProxyInfo->qstrProxyPort.toInt());
proxy.setUser(pProxyInfo->qstrProxyUserName);
proxy.setPassword(pProxyInfo->qstrProxyPassWord);
qnam->setProxy(proxy);
Re: For help!why QHttp,QNetworkProxy set proxy with username and password failed?
Yes :)
You should read about Qt signals and slots. I think you need a slot that sets the authentication parameters.
http://doc.trolltech.com/4.5/signalsandslots.html
Re: For help!why QHttp,QNetworkProxy set proxy with username and password failed?
Add slot and response Func:reponseRecue,but stiil failed ,why???,It seems that i cant get the response message,bcz reponseRecue,not entered,and the dialogue says:detecting...
why???
[
QNetworkAccessManager* qnam = new QNetworkAccessManager(this);
connect(qnam, SIGNAL(finished(QNetworkReply *)), this, SLOT(reponseRecue(QNetworkReply*)));
connect(qnam, SIGNAL(authenticationRequired(QNetworkReply*,QAuth enticator*)),
this, SLOT(authenticate(QNetworkReply*,QAuthenticator*)) );
connect(qnam, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)),
this, SLOT(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)));
//begin mod
QNetworkProxy proxy;
proxy.setType(QNetworkProxy::HttpProxy);
/*proxy.setType(QNetworkProxy::Socks5Proxy);*/
proxy.setHostName(pProxyInfo->qstrProxyServerName);
proxy.setPort(pProxyInfo->qstrProxyPort.toInt());
proxy.setUser(pProxyInfo->qstrProxyUserName);
proxy.setPassword(pProxyInfo->qstrProxyPassWord);
//QNetworkProxy::setApplicationProxy(proxy);*/
/*m_pTestHttpObj->setProxy(proxy);*/
qnam->setProxy(proxy);
....
....
void XXX::reponseRecue(QNetworkReply* reply)
{
CDlgSetting* pSet = (CDlgSetting*)m_pSet;
if (reply->error() == QNetworkReply::NoError)
{
pSet->OnCheckNetConnectSuccess();
qDebug() << reply->readAll();
QMessageBox::information(0, tr("Connection"), tr("ok"));
}
else
{
pSet->OnCheckNetConnectFaild();
QMessageBox::information(0, tr("Connection"), tr("Err !"));
}
m_pSet = NULL;
delete reply;
}
Re: For help!why QHttp,QNetworkProxy set proxy with username and password failed?
Please look into demos/browser/networkaccessmanager.cpp in the Qt source to see how proxyAuthenticationRequired is used there.
Re: For help!why QHttp,QNetworkProxy set proxy with username and password failed?
QNetworkaccessmanager is worked!
thanks a lot ,mgoetz!
many thanks!
Re: For help!why QHttp,QNetworkProxy set proxy with username and password failed?