Results 1 to 7 of 7

Thread: Example for Http put

  1. #1
    Join Date
    Sep 2010
    Posts
    4
    Qt products
    Qt/Embedded
    Platforms
    Symbian S60 Maemo/MeeGo

    Default Example for Http put

    Hello All

    This is my first post here and indeed this is a very informative forum. :-)

    Can any body provide me an example of doing http put using QNetworkAccessManger class.

    I tried a lot but was not successful.

    Regards,

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Example for Http put

    Please post the errors you get and the code you tried.

  3. #3
    Join Date
    Sep 2010
    Posts
    4
    Qt products
    Qt/Embedded
    Platforms
    Symbian S60 Maemo/MeeGo

    Default Re: Example for Http put

    hello tbscope

    thanks for the reply.

    I am not getting any errors but the at the same time my data is also not going to the server following is the code i tried:

    Qt Code:
    1. QNetworkRequest request(QUrl("my url"));
    2.  
    3. QByteArray data;
    4. QUrl param;
    5. param.addEncodedQueryItem("user_credentials",singleaccesstoken.toAscii());
    6. param.addEncodedQueryItem("login","username");
    7. param.addEncodedQueryItem("password","pwd");
    8.  
    9. data.append(param.toString().toAscii());
    10. data.remove(0,1);
    11.  
    12. nam->put(request,data);
    13.  
    14. where nam is QNetworkAccessManager.
    To copy to clipboard, switch view to plain text mode 

    I guess the way i am doing is wrong as this is my first time i am working with put with http.

    Please let me know where i need to make changes.

    Regards,

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Example for Http put

    Your use of a QUrl and addEncodedQueryItem and converting the results to a string certainly seem weird to me.
    And are you sure the server accepts a PUT request?

    Can you debug the exact data you send to see if it is really what you want to send?

  5. #5
    Join Date
    Sep 2010
    Posts
    4
    Qt products
    Qt/Embedded
    Platforms
    Symbian S60 Maemo/MeeGo

    Default Re: Example for Http put

    hello tbscope

    Thats what i want to know, in what manner i should send data when using http put, can you make me clear with that first.

    Secondly yes the server accepts data using http put. I just tried to do what i used during http post, so it will great if you can make me understand with the format i need to send the data to the server.

    Regards,

  6. #6
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Example for Http put

    Add these lines to your code, then look if it is exactly the same as you tried before (when it worked).

    Qt Code:
    1. #include <QDebug>
    2. qDebug() << param.toString().toAscii();
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Sep 2010
    Posts
    4
    Qt products
    Qt/Embedded
    Platforms
    Symbian S60 Maemo/MeeGo

    Default Re: Example for Http put

    Quote Originally Posted by tbscope View Post
    Add these lines to your code, then look if it is exactly the same as you tried before (when it worked).
    Hello

    I guess there is a misunderstanding i never said that it worked for me earlier, the post methods for a different API call in the server works for me but now i have to send a put request to the server with parameters and i am unable to do that . :-(

Similar Threads

  1. Qt Http implementation
    By ada10 in forum Newbie
    Replies: 6
    Last Post: 11th August 2010, 23:36
  2. Http post
    By Max123 in forum Qt Programming
    Replies: 1
    Last Post: 30th May 2010, 13:43
  3. HTTP request
    By Trok in forum Qt Programming
    Replies: 9
    Last Post: 5th January 2010, 14:49
  4. XML http?
    By Mohd.Imran in forum Newbie
    Replies: 2
    Last Post: 23rd June 2009, 10:11
  5. http connection
    By bhogasena in forum Qt Programming
    Replies: 12
    Last Post: 25th February 2009, 11:32

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.