Results 1 to 14 of 14

Thread: QNetworkAccessManager proxy issue

  1. #1
    Join Date
    Jan 2010
    Posts
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Exclamation QNetworkAccessManager proxy issue

    I'm having problems getting through a proxy. If I use the following code.

    Qt Code:
    1. QWebView a;
    2. a.load(QUrl("http:\\google.co.uk"));
    3. a.show();
    To copy to clipboard, switch view to plain text mode 
    The request fails, because I'm behind a proxy. Which is fine and I understand that. So if I amend the code to :

    Qt Code:
    1. QNetworkProxyFactory::setUseSystemConfiguration ( true) ;
    2. QWebView a;
    3. a.load(QUrl("http:\\google.co.uk"));
    4. a.show();
    To copy to clipboard, switch view to plain text mode 

    Everything works fine. I see the google page and I'm not prompted to input my proxy user name or password.
    Now this is where I have my problem. I don't want to use a GUI. I'm trying to automate a process at work so I thought I would use QNetworkAccessManager to the same result.

    So heres my code :

    Qt Code:
    1. QUrl a("http://google.co.uk");
    2. QNetworkAccessManager *manager = new QNetworkAccessManager(this);
    3.  
    4. QNetworkProxyQuery npq(a);
    5. QList<QNetworkProxy> listOfProxies = QNetworkProxyFactory::systemProxyForQuery(npq);
    6.  
    7. if (listOfProxies.count() !=0){
    8. if (listOfProxies.at(0).type() != QNetworkProxy::NoProxy) {
    9. manager->setProxy(listOfProxies.at(0));
    10. std::cerr << "Using Proxy " << listOfProxies.at(0).hostName().toStdString() << "\n";
    11. }
    12. }
    13.  
    14. connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(outPutPage(QNetworkReply*)));
    15. manager->get(QNetworkRequest(a));
    To copy to clipboard, switch view to plain text mode 
    Now without a proxy this code works fine and I see the HTML printed to the screen. However when running behind a proxy (that requires authentication) I see the code telling me its "Using Proxy" but the code fails even if I supply a valid username and password, it just keeps reporting that the proxy requires authentication. I have tried many different combinations, using QNetworkProxyFactory::setUseSystemConfiguration ( true) ; setting the application proxy.

    Does anyone have any idea how I might resolve this. Or is there a class I can use in the QWebKit that doesn't have the over head of rendering. I'm only interested in the data being sent a received. Or doesn't anyone know what the QWebKit class does differently to QNetworkAccessManager::setProxy?

    All help will be appreciated.

    Regards

    Dan
    Last edited by wysota; 14th January 2010 at 19:21. Reason: reformatted to look better

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

    Default Re: QNetworkAccessManager proxy issue

    How do you provide authentication?
    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
    Jan 2010
    Posts
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QNetworkAccessManager proxy issue

    By trapping the proxyAuthenticationRequired signal and setting the username and password in the SLOT.

    But the fact that it asks me for a username and password is confusing me. The proxy is self authenticating, and the QWebKit doesn't ask for the proxy username or password so why should this work any different?

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

    Default Re: QNetworkAccessManager proxy issue

    What do you mean by "self authenticating"? Did you try setting an individual proxy using QNetworkProxy to see if it changes anything?
    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.


  5. #5
    Join Date
    Jan 2010
    Posts
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QNetworkAccessManager proxy issue

    Don't worry about the "Self Authenticating" bit. I just ment in IE i don't have to enter my password because it know who I am, and the QWebView appears to also know who I am.... but thats not really the issue so sorry about that.

    Yes I have also created a QNetworkProxy and setting the username, password, type, port and hostname manually and then passing that as an object. But the proxyserverrequiresauthentication signal keeps fireing.
    Thanks for you help so far on this. Any other ideas would be great. The only think I can think of is maybe I need to pass the domain name as well as the username. So i tried passing domain\username but it HTML encodes the \ which I don't think the proxy will like.

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

    Default Re: QNetworkAccessManager proxy issue

    Is your application multithreaded?
    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.


  7. #7
    Join Date
    Jan 2010
    Posts
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QNetworkAccessManager proxy issue

    No not at this stage. Do you have any example project that I could download to see if that works though the proxy server?

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

    Default Re: QNetworkAccessManager proxy issue

    No, sorry

    So let's sum things up... you have code that works when used with QWebView but the same code doesn't work when used with pure QNetworkAccessManager. Is that correct? Can you craft a minimal compilable example reproducing the problem and paste it here?
    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.


  9. #9
    Join Date
    Sep 2009
    Posts
    36
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QNetworkAccessManager proxy issue

    As far as I know you have to connect a slot to the signal proxyAuthenticationRequired from QNetworkAccessManager. In the connected slot you will have to set the proxy. This settings are remebered according to QtDoc so te signal is only emitted once.
    I currently don't have time to write any dummy code.

  10. #10
    Join Date
    Dec 2009
    Posts
    14
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QNetworkAccessManager proxy issue

    In your first code post ...u mentioned that you used QNetworkProxyFactory::setUseSystemConfiguration ( true) ; for QWebView to load the page
    behind proxy.But from where u got this setUseSystemConfiguration (true); functionality.
    QNetworkProxyFactory not having this...


    Please respond... i need this very badly...struggling with proxy problen in QWebView...

  11. #11
    Join Date
    Jan 2010
    Posts
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QNetworkAccessManager proxy issue

    Thanks wysota.

    I've upload two projects which are my prototype projects and are only small. It'd be good to find out if they work behind your proxy. Also ansar make sure you're using the latest version of qt it's defiantly in 4.6 http://qt.nokia.com/doc/4.6/qnetworkproxyfactory.html

    TestQNetworkAccessManager.zip and testQWebView.zip

    Thanks again, be good to know if I've done something stupid, or even if they work your end.

  12. #12
    Join Date
    Jan 2013
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QNetworkAccessManager proxy issue

    It looks good to me.
    The only thing, you have to pass login and password to the proxy:

    Qt Code:
    1. void test::proxyNeedsUserName(QNetworkProxy nr,QAuthenticator* auth){
    2. auth->setUser("yourlogin");
    3. auth->setPassword("yourpassword");
    4. nr.setUser("yourlogin");
    5. nr.setPassword("yourpassword");
    6. }
    To copy to clipboard, switch view to plain text mode 

  13. #13
    Join Date
    Feb 2013
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QNetworkAccessManager proxy issue

    Hi, guys,

    I think the issue was already solved, but I want to inform what I've found.

    In old Qt Versions (up to 4.8.x) signal ProxyAutenticationRequired is emitted every request, and there is no solution but repeatedly send username and password.
    Qt 5.3.1 (and may more later's) QNetworkAccessManager keeps user credentials in cache and if they are correct it doesn't emit this signal, if they are not you must answer on that signal, but keep in mind if the site has prefix https, which is usual in today life, the program crashes. This is a bag of Qt 5.3.1. For windows there are patches, but the problem didn't fully solved.

    I hope, this info will be useful for you.

    Regards,
    Radmir

  14. #14
    Join Date
    Dec 2017
    Posts
    12
    Qt products
    Platforms
    Android

    Default Re: QNetworkAccessManager proxy issue

    There can also be problems with particular proxy services... Use this source to test every VPN service, cause I've heard some of them can cause troubles like that.

Similar Threads

  1. HTTP POST / Proxy Authentication issue
    By dekc99 in forum Qt Programming
    Replies: 2
    Last Post: 10th August 2011, 09:59
  2. Replies: 0
    Last Post: 21st December 2009, 05:04
  3. How to Login using QNetworkAccessManager?
    By cydside in forum Newbie
    Replies: 1
    Last Post: 31st August 2009, 21:41
  4. QNetworkAccessManager vs QHttp
    By jiveaxe in forum Newbie
    Replies: 3
    Last Post: 17th February 2009, 14:07
  5. Custom proxy model issue
    By Khal Drogo in forum Qt Programming
    Replies: 13
    Last Post: 30th November 2007, 12:41

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.