Results 1 to 4 of 4

Thread: QNetworkAccessManager strange problem and behavior

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2013
    Posts
    8
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo

    Default QNetworkAccessManager strange problem and behavior

    Hi all, I have strange problem with QNetworAccessManager.

    I was trying to make a web service application with Qt with OAuth.
    I manage to create my own OAuth service for my need based on QOAuth.
    But the problem is not in OAuth.
    The problem is in QNetworkAccessManager.


    For example, there is this url that produced by OAuth,
    if I open that url with QNetworkManager, like this
    Qt Code:
    1. QNetworkAccessManager manager = new QNetworkAccessManager();
    2. connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(replyFinished(QNetworkReply *)));
    3.  
    4. // this is just for illustration not real consumer key and signature, the link produced by my OAuth
    5. QString url = "https://www.my-example-site.com/oauth/content?oauth_consumer_key=1234567890&oauth_nonce=1824974157&oauth_signature=aBAy4KWZcs5762N4VPjiDj%2FtyqY%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1366080188&oauth_version=1.0";
    6. QNetworkRequest request;
    7. request.setUrl( url );
    8. request.setRawHeader( "Content-Type", "application/x-www-form-urlencoded");
    9. QNetworkReply *reply = manager->get( request );
    To copy to clipboard, switch view to plain text mode 

    It gave error "Host Require Authentication", "Error 401", "oauth_problem=invalid_signature"

    but, if I generate new url with my OAuth and open that link on firefox, it will produce correct result.
    I also try libcurl for c++.
    Qt Code:
    1. CURL* curl;
    2.  
    3. curl_global_init(CURL_GLOBAL_ALL);
    4. curl = curl_easy_init();
    5.  
    6. // another illustration, not real consumer key and signature
    7. curl_easy_setopt(curl, CURLOPT_URL, "https://www.my-example-site.com/oauth/content?oauth_consumer_key=1234567890&oauth_nonce=1824974157&oauth_signature=a9Vy4+CZcs5762N4VPjiDj%2FtyqY%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1366080200&oauth_version=1.0");
    8. // curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &writeCallback);
    9. curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
    10.  
    11. curl_easy_perform(curl);
    12.  
    13. curl_easy_cleanup(curl);
    14. curl_global_cleanup();
    To copy to clipboard, switch view to plain text mode 
    It gave correct result and no error.

    I also try QHttp.
    Qt Code:
    1. QHttp http = new QHttp();
    2. connect(http, SIGNAL(requestFinished(int,bool)), this, SLOT(requestFinished(int,bool)));
    3. http->setHost("https://www.my-example-site.com", QHttp::ConnectionModeHttps);
    4. http->get("/oauth/content?oauth_consumer_key=1234567890&oauth_nonce=1824974157&oauth_signature=a9Vy4+ABCDEF62N4VPjiDj%2FtyqY%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1366080300&oauth_version=1.0");
    To copy to clipboard, switch view to plain text mode 
    It also gave correct result and no error.


    So, what is wrong with the way I use QNetworkAccessManager?
    I try it in qtcreator with Qt 4.8 and Qt 5, but no luck.
    They gave same error result.

    I want to keep on using QNetworkAccessManager, but if I can't resolve this problem, what should I do?
    Should I use curl or QHttp? or is there another network library that I can use?

    thank you.
    Last edited by creation; 16th April 2013 at 04:20.

Similar Threads

  1. Qt process strange behavior
    By rspock in forum Newbie
    Replies: 5
    Last Post: 15th March 2013, 17:11
  2. setCellWidget - strange behavior
    By Archa4 in forum Newbie
    Replies: 5
    Last Post: 28th April 2011, 08:26
  3. QComboBox strange behavior
    By Antebios in forum Newbie
    Replies: 2
    Last Post: 31st March 2009, 23:50
  4. Strange resize behavior
    By Lykurg in forum Newbie
    Replies: 3
    Last Post: 9th January 2007, 13:56
  5. scrollbars strange behavior
    By siniy in forum Qt Programming
    Replies: 6
    Last Post: 29th December 2006, 10:27

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.