[Interest] Http Proxy connection woes
Jason Kretzer
Jason at gocodigo.com
Mon Apr 6 16:52:01 CEST 2015
Still trying to figure this out.
Here is the code again. I have distilled this down quite a bit trying to figure it out and here is the code that I am currently using.
In main:
QNetworkProxyFactory::setUseSystemConfiguration(true);
QNetworkProxy proxy = QNetworkProxy::applicationProxy();
proxy.setUser(uname);
proxy.setPassword(pw);
Then I call:
bool hasAccess = ServerCommunication().connectToPort(“http://www.anoutsidesite.com”, 80);
//this returns false
bool ServerCommunication::connectToPort(QString server, int port)
{
QTcpSocket socket;
QNetworkProxy proxy = QNetworkProxy::applicationProxy();
socket.setProxy(proxy);
QObject::connect(&socket,SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), this, SLOT(onProxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)));
socket.connectToHost(server,port);
if(socket.waitForConnected(20000)) {
qDebug() << "Connect to Host success!";
socket.close();
return true;
}
qDebug() << "ConnectToHost Error String: " << socket.errorString();
socket.close();
return false;
}
Here is the SLOT from above
void ServerCommunication::onProxyAuthenticationRequired(const QNetworkProxy &p, QAuthenticator *auth)
{
qDebug() << "Calling onProxyAuthenticationRequired method";
QNetworkProxy proxy = QNetworkProxy::applicationProxy();
auth->setUser(proxy.user());
auth->setPassword(proxy.password());
}
I set the timeout to 20seconds on the waitForConnected.
Upon running the above, I get this:
[10:06:29]: DEBUG: Calling onProxyAuthenticationRequired method
[10:06:29]: DEBUG: Calling onProxyAuthenticationRequired method
[10:06:29]: DEBUG: Calling onProxyAuthenticationRequired method
…these repeat for 20 seconds…
[10:06:48]: DEBUG: Calling onProxyAuthenticationRequired method
[10:06:48]: DEBUG: Calling onProxyAuthenticationRequired method
[10:06:49]: DEBUG: Calling onProxyAuthenticationRequired method
[10:06:49]: DEBUG: Calling onProxyAuthenticationRequired method
And finally ends with this.
[10:06:49]: DEBUG: ConnectToHost Error String: "Socket operation timed out"
I am totally at a loss on this. I have googled this for hours looking for different ideas. Would using a QNetworkAccessManager fare any better than the QTcpSocket? Am I using the Qauthenticator correctly? Should I further increase the timeout? Do I need to disconnect the SIGNAL from inside the SLOT to keep it from being called so many times — ie. Is that resetting the progress and never allowing it to properly authenticate?
Thoughts?
-Jason
//------------------------------//
Jason R. Kretzer
Lead Application Developer
Jason at gocodigo.com<mailto:Jason at gocodigo.com>
//-----------------------------//
From: Thiago Macieira <thiago.macieira at intel.com<mailto:thiago.macieira at intel.com>>
To: "interest at qt-project.org<mailto:interest at qt-project.org>" <interest at qt-project.org<mailto:interest at qt-project.org>>
Subject: Re: [Interest] Http Proxy connection woes
On Tuesday 24 February 2015 13:24:24 Jason Kretzer wrote:
Here is the thing:
I have software that is generally “proxy aware.” I have it running behind
other proxies and they seem to work. The software is now running behind
another proxy and I cannot seem to connect to the outside world using it.
Here is the code in main.cpp:
QNetworkProxy proxy;
proxy.setType(QNetworkProxy::HttpProxy);
proxy.setHostName(hostName);
proxy.setPort(port);
proxy.setUser(uname);
proxy.setPassword(pw);
QNetworkProxy::setApplicationProxy(proxy);
I have validated with the client that it is an HttpProxy. I have left out
how I get the settings, but they are accurate and in the proper format.
The uname/pw are windows authentication and I tried it with both
“adomain\bob” and “bob at domain.com<mailto:“bob at domain.com>”.
What's the authentication method this proxy server uses? HTTP Basic? Or is it
NTLM?
Anyway, when it runs, this line — qDebug() << "ConnectToHost Error String:
" << socket.errorString(); Prints:
DEBUG: ConnectToHost Error String: "Error communicating with HTTP proxy”
Just as an extra piece of information, I also tried it with a SOCKS5
ProxyType and the line printed: DEBUG: ConnectToHost Error String: "Socket
operation timed out"
Is there some obvious thing I am missing here?
500 milliseconds may be too short. You may be facing network congestion.
Increase to 10 seconds.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
_______________________________________________
Interest mailing list
Interest at qt-project.org<mailto:Interest at qt-project.org>
http://lists.qt-project.org/mailman/listinfo/interest
-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2015.0.5645 / Virus Database: 4293/9166 - Release Date: 02/23/15
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150406/e7258402/attachment.html>
More information about the Interest
mailing list