Hi,
i am trying to make an http request over a proxy server.
The proxy is ISA proxy server. i use QTcpSocket class
the IP of destination : xx.xx.xx.xx port : 80
the IP of proxy server : yy.yy.yy.yy port : 8080
when i write a code like below:
s.connectToHost(xx.xx.xx.xx,80);
if (!s.waitForConnected(15))
{
throw s.errorString();
}
QTcpSocket s;
s.setProxy(QNetworkProxy(QNetworkProxy::DefaultProxy, "yy.yy.yy.yy",8080));
s.connectToHost(xx.xx.xx.xx,80);
if (!s.waitForConnected(15))
{
throw s.errorString();
}
To copy to clipboard, switch view to plain text mode
it never connects, throws exception telling "socket timeout"
I tried setting socket type HttpProxy. it gives exception "Error communicating with HttpProxy"
then i tried to connect proxy server instead of host :
s.connectToHost(yy.yy.yy.yy,8080);
if (!s.waitForConnected(15))
{
throw s.errorString();
}
QTcpSocket s;
s.setProxy(QNetworkProxy(QNetworkProxy::DefaultProxy, "yy.yy.yy.yy",8080));
s.connectToHost(yy.yy.yy.yy,8080);
if (!s.waitForConnected(15))
{
throw s.errorString();
}
To copy to clipboard, switch view to plain text mode
i put the information about the host into the http request. and post the request to the proxy server. it worked.
However this only works for anonymous connections.
So the problem occurs when proxy server requires authentication. I wrote the code below:
s.connectToHost(yy.yy.yy.yy,8080);
if (!s.waitForConnected(15))
{
throw s.errorString();
}
s.write(requestbytes);
s.waitForReadyRead(-1)
QTcpSocket s;
s.setProxy(QNetworkProxy(QNetworkProxy::DefaultProxy, "yy.yy.yy.yy",8080,username,password));
s.connectToHost(yy.yy.yy.yy,8080);
if (!s.waitForConnected(15))
{
throw s.errorString();
}
s.write(requestbytes);
s.waitForReadyRead(-1)
QByteArray response = s.readAll();
To copy to clipboard, switch view to plain text mode
the response was like below with status code 407
"HTTP 407 Proxy Authentication Required- The ISA Server requires authorization to fulfill the request
Access to the Web Proxy service is denied
..."
I even used proxyAuthenticationRequired(...) signal and provided the credentials in a slot. but it never enters that slot.
am i missing something ? what else can i do to achieve authentication to the proxy server?
thanks..
Bookmarks