Results 1 to 6 of 6

Thread: QNetworkAccessManager Http Basic Authentication?

  1. #1
    Join Date
    Dec 2010
    Posts
    2
    Qt products
    Qt4

    Default QNetworkAccessManager Http Basic Authentication?

    Hi, I am trying to send HTTP commands to some hardware(the server) which requries authentication before I can communicate. I left visual studio and converted my code to QT because I was sure it would be much easier to accomplish, but I am having problem just getting started.

    1) Should I just use QTcpSockets and try to authenticate them with my username and password, or stick with QNetworkAccessManager
    2) How do I even use QNetworkAccessManager to send out a string to a server? And how do I set up my port Number and hostname when using QNetworkAccessManager?

    Any help is greatly appeciated, I would post some code but I mean im confused on just how to start using QNetworkAccessManager

    -Thanks

  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: QNetworkAccessManager Http Basic Authentication?

    Quote Originally Posted by jloundy View Post
    2) How do I even use QNetworkAccessManager to send out a string to a server?
    Most likely using QNetworkAccessManager::get() or QNetworkAccessManager::post().

    And how do I set up my port Number and hostname when using QNetworkAccessManager?
    Place them as part of the URL you pass to get() or post().
    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
    Jul 2009
    Posts
    74
    Thanks
    2
    Thanked 6 Times in 6 Posts

    Default Re: QNetworkAccessManager Http Basic Authentication?

    example:
    QNetworkRequest * nr = new QNetworkRequest(QUrl("https://www.whatever.com/"));
    nr->setRawHeader("Authorization", "Basic " + QByteArray(QString("%1:%2").arg("username").arg("p assword").toAscii()).toBase64());

  4. #4
    Join Date
    Dec 2010
    Posts
    2
    Qt products
    Qt4

    Default Re: QNetworkAccessManager Http Basic Authentication?

    Thank you guys for the help. Basically the hardware I am working with is controlled by http commands sent through a web browser. I am trying to bypass the webbrowser and send them straight to the hardware. Im getting a 401 unauthorized error but i connected the signal and slot to handle the authentication process. Do you guys have any ideas?

  5. #5
    Join Date
    Jul 2009
    Posts
    74
    Thanks
    2
    Thanked 6 Times in 6 Posts

    Default Re: QNetworkAccessManager Http Basic Authentication?

    sorry... i don't understand you....
    maybe you are not encoding correctly the request??

    anyway.... you can use a http debugger (like Fiddler -it's free-) and mimic the same requests... (maybe you must set up an user-agent... or something like that)

  6. #6
    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: QNetworkAccessManager Http Basic Authentication?

    Quote Originally Posted by jloundy View Post
    Im getting a 401 unauthorized error but i connected the signal and slot to handle the authentication process.
    Show us contents of the slot connected to the authenticationRequired() signal.
    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.


Similar Threads

  1. HTTP POST / Proxy Authentication issue
    By dekc99 in forum Qt Programming
    Replies: 2
    Last Post: 10th August 2011, 09:59
  2. Basic Authentication
    By lyhoanghai in forum Qt Programming
    Replies: 2
    Last Post: 16th May 2011, 11:00
  3. HTTPS Client Authentication (Mutual Authentication)
    By cbourne in forum Qt Programming
    Replies: 3
    Last Post: 5th December 2010, 11:51
  4. HTTP GET authentication does not proceed
    By SailingDreams in forum Qt Programming
    Replies: 2
    Last Post: 1st June 2009, 01:27
  5. QHTTP does not see tunneled TCP HTTP OK authentication response
    By SailingDreams in forum Qt Programming
    Replies: 6
    Last Post: 23rd May 2009, 09:39

Tags for this Thread

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.