Results 1 to 10 of 10

Thread: For help!why QHttp,QNetworkProxy set proxy with username and password failed?

  1. #1
    Join Date
    Nov 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Unhappy 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

  2. #2
    Join Date
    Oct 2009
    Posts
    37
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default 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.
    Disclaimer: Although I work on Qt for Nokia, anything I post here is personal

  3. #3
    Join Date
    Nov 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default 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);*/

  4. #4
    Join Date
    Oct 2009
    Posts
    37
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default 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
    Disclaimer: Although I work on Qt for Nokia, anything I post here is personal

  5. #5
    Join Date
    Nov 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default 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);

  6. #6
    Join Date
    Oct 2009
    Posts
    37
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default 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
    Disclaimer: Although I work on Qt for Nokia, anything I post here is personal

  7. #7
    Join Date
    Nov 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default 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;
    }

  8. #8
    Join Date
    Oct 2009
    Posts
    37
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default 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.
    Disclaimer: Although I work on Qt for Nokia, anything I post here is personal

  9. The following user says thank you to mgoetz for this useful post:

    kissfire (16th November 2009)

  10. #9
    Join Date
    Nov 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Talking Re: For help!why QHttp,QNetworkProxy set proxy with username and password failed?

    QNetworkaccessmanager is worked!
    thanks a lot ,mgoetz!
    many thanks!

  11. #10
    Join Date
    Oct 2009
    Posts
    37
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: For help!why QHttp,QNetworkProxy set proxy with username and password failed?

    Glad it works
    Disclaimer: Although I work on Qt for Nokia, anything I post here is personal

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.