Results 1 to 4 of 4

Thread: QTcpSocket proxy authentication problem

  1. #1
    Join Date
    Aug 2008
    Posts
    27
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTcpSocket proxy authentication problem

    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:

    Qt Code:
    1. s.setProxy(QNetworkProxy(QNetworkProxy::DefaultProxy, "yy.yy.yy.yy",8080));
    2.  
    3. s.connectToHost(xx.xx.xx.xx,80);
    4.  
    5. if (!s.waitForConnected(15))
    6. {
    7. throw s.errorString();
    8. }
    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 :

    Qt Code:
    1. s.setProxy(QNetworkProxy(QNetworkProxy::DefaultProxy, "yy.yy.yy.yy",8080));
    2.  
    3. s.connectToHost(yy.yy.yy.yy,8080);
    4.  
    5. if (!s.waitForConnected(15))
    6. {
    7. throw s.errorString();
    8. }
    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:

    Qt Code:
    1. s.setProxy(QNetworkProxy(QNetworkProxy::DefaultProxy, "yy.yy.yy.yy",8080,username,password));
    2.  
    3. s.connectToHost(yy.yy.yy.yy,8080);
    4.  
    5. if (!s.waitForConnected(15))
    6. {
    7. throw s.errorString();
    8. }
    9.  
    10. s.write(requestbytes);
    11. s.waitForReadyRead(-1)
    12. 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..
    Last edited by arbi; 11th September 2009 at 07:58.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTcpSocket proxy authentication problem

    How about using QNetworkAccessManager instead of QTcpSocket?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Aug 2008
    Posts
    27
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTcpSocket proxy authentication problem

    yes i tried that class also . but i couldnt get it work. Maybe i am using that wrong.

    When using QTcpSocket i connect to the proxy server.

    Qt Code:
    1. s.connectToHost("yy.yy.yy.yy",8080);// yy.yy.yy.yy:8080 is the proxy address
    To copy to clipboard, switch view to plain text mode 

    and send server the message below;

    POST http://xx.xx.xx.xx/ HTTP/1.1
    User-Agent: TSS Client
    Host: xx.xx.xx.xx
    Proxy-Connection: Keep-Alive
    Content-Length: 61
    Content-Type: application/timestamp-query
    Identity: 304d0201010410a6ee0e6ddf04fd7e0f36a41708071a850202 07d004105f0ffc985e9c03361f5e11d8bf674e10042007320d c4190c712f1dfb94ced2e983a886674d2a9600ca3fec5e5c56 31e9d73c

    <...requestbody...>




    how can i do the same with QNetworkAccessManager?
    I read the doc about QNetworkAccessManager;
    I set the proxy of manager with setProxy() and tried post(...) method with several combinations , connected all of the signals it emits to slots. but couldnt see anything coming from the server.

    can you explain how can i use QNetworkAccessManager to make the above request.?
    How should i init QNetworkRequest object when posting? should i post to my destination(xx.xx.xx.xx)
    or the proxy server(yy.yy.yy.yy).

    a piece of code ?

    thanks.

  4. #4
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Default Re: QTcpSocket proxy authentication problem

    Generally speaking you have to query your destination directly, and set the proxy ip/user/pass in QNetworkProxy .

    But..I usually work with QNetworkAccessManager behind a ISA proxy when I'm testing my app at work, and I can't connect to the proxy server directly because...my ISA server uses NTLM v2 hashes and Qt don't support them.
    At least until version 4.5 (from QAuthenticator documentation):
    QAuthenticator supports the following authentication methods:

    Basic
    NTLM version 1
    Digest-MD5
    Note that, in particular, NTLM version 2 is not supported.
    To my surprise version 4.5.2 misses this notice, but you can read from google cache: http://209.85.129.132/search?q=cache...&ct=clnk&gl=it

    It doesn't seem that nokia improved qauthenticator (at least there's nothing about it in 4.5.1 and 4.5.2 changelog), and anyway it it still not working for me.

    There IS a solution indeed, at least for your development machine: use CNTLM on your computer, and point your qt app to the following proxy "localhost:3128" (that is default cntlm port).
    Obviously you need to configure and run CNTLM before

    Hope this helps

Similar Threads

  1. Challenging QTcpSocket reliability problem
    By Raccoon29 in forum Qt Programming
    Replies: 3
    Last Post: 13th January 2009, 10:38
  2. array of pointers to QtcpSocket
    By gQt in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 16th June 2008, 09:15
  3. QTcpServer & QTcpSocket questions...
    By jxmot in forum Qt Programming
    Replies: 2
    Last Post: 24th April 2008, 21:38
  4. QTcpSocket and libssh2 ...
    By sandros in forum Qt Programming
    Replies: 6
    Last Post: 21st November 2007, 22:34
  5. Strange QTcpSocket behavior (debugged with Ethereal)
    By mdecandia in forum Qt Programming
    Replies: 23
    Last Post: 28th May 2007, 20:44

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.