Results 1 to 5 of 5

Thread: QNetworkAccessManager PUT method delete data over server

  1. #1
    Join Date
    Jun 2015
    Posts
    87
    Thanks
    20
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default QNetworkAccessManager PUT method delete data over server

    Hi,

    I'm trying to update JSON data over a server but it is not updating, its deleting everything even if I send blank data.

    Find the implementation below,

    Qt Code:
    1. QNetworkAccessManager m_mgr;
    2. QNetworkRequest m_request;
    3. QNetworkReply *m_reply;
    4. QUrl url("https://api.predic8.de/shop/products/10");
    5. m_request.setUrl(url);
    6.  
    7. QVariantMap data;
    8. data.insert("name", "Oranges");
    9.  
    10. QJsonDocument jsonData = QJsonDocument::fromVariant(data);
    11. m_reply = m_mgr.put(m_request, jsonData.toJson(QJsonDocument::Indented));
    12. connect(m_reply, &QNetworkReply::finished, m_reply, &QNetworkReply::deleteLater);
    To copy to clipboard, switch view to plain text mode 

    Please help me why it delete the data instead of an update?

  2. #2
    Join Date
    Jun 2015
    Posts
    87
    Thanks
    20
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QNetworkAccessManager PUT method delete data over server

    I found the solution,
    Setting header solved my issue,
    Qt Code:
    1. m_request.setHeader( QNetworkRequest::ContentTypeHeader, "application/json" );
    To copy to clipboard, switch view to plain text mode 
    Technically I don't understand why its deleting data if I didn't set header.
    Can someone explain to me this or does it mandatory to use header?

    Thanks

  3. #3
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    446
    Thanked 61 Times in 57 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QNetworkAccessManager PUT method delete data over server

    Quote Originally Posted by npatil15 View Post
    Can someone explain to me this or does it mandatory to use header?
    How should we know what your 'server' does at all?

  4. #4
    Join Date
    Jun 2015
    Posts
    87
    Thanks
    20
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QNetworkAccessManager PUT method delete data over server

    Hi ChristianEhrlicher,

    I'm using a local server, and follow this below tutorial for creating this local server,
    https://medium.com/codingthesmartway...r-36da8680136d

  5. #5
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    446
    Thanked 61 Times in 57 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QNetworkAccessManager PUT method delete data over server

    Since this is not C++/Qt I can't help debugging the server.

Similar Threads

  1. Post some data onto the local server by QNetworkAccessManager(Qt5)
    By stereoMatching in forum Qt Programming
    Replies: 2
    Last Post: 10th March 2014, 00:13
  2. QNetworkAccessManager timeout when server is down?
    By martinn in forum Qt Programming
    Replies: 8
    Last Post: 9th January 2014, 16:32
  3. When to delete QNetworkAccessManager pointer?
    By veroslav in forum Newbie
    Replies: 4
    Last Post: 30th August 2012, 11:08
  4. QNetworkAccessmanager and ICY-Server
    By jörg in forum Qt Programming
    Replies: 2
    Last Post: 12th August 2011, 12:36
  5. QNetworkAccessManager and post method
    By sabbu in forum Newbie
    Replies: 12
    Last Post: 16th June 2011, 23:01

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.