Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QNetworkAccessManager PUT method delete Json data over server
Forum Updated to NodeBB v4.3 + New Features

QNetworkAccessManager PUT method delete Json data over server

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 449 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    npatil15
    wrote on 28 Jun 2019, 05:22 last edited by
    #1

    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,

            QNetworkAccessManager m_mgr;
            QNetworkRequest m_request;
            QNetworkReply *m_reply;
            QUrl url("https://api.predic8.de/shop/products/10");
            m_request.setUrl(url);
         
            QVariantMap data;
            data.insert("name", "Oranges");
         
            QJsonDocument jsonData = QJsonDocument::fromVariant(data);
            m_reply = m_mgr.put(m_request, jsonData.toJson(QJsonDocument::Indented));
            connect(m_reply, &QNetworkReply::finished, m_reply, &QNetworkReply::deleteLater);
    

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

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 28 Jun 2019, 05:41 last edited by
      #2

      Hi,

      That's completely unrelated to Qt. You should check server side the implementation of the "PUT" handler as it's there that this stuff is happening.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • N Offline
        N Offline
        npatil15
        wrote on 28 Jun 2019, 06:42 last edited by
        #3

        I found the solution,
        Setting header solved my issue,

        m_request.setHeader( QNetworkRequest::ContentTypeHeader, "application/json" );
        

        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

        J 1 Reply Last reply 28 Jun 2019, 07:27
        0
        • N npatil15
          28 Jun 2019, 06:42

          I found the solution,
          Setting header solved my issue,

          m_request.setHeader( QNetworkRequest::ContentTypeHeader, "application/json" );
          

          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

          J Offline
          J Offline
          JKSH
          Moderators
          wrote on 28 Jun 2019, 07:27 last edited by
          #4

          @npatil15 said in QNetworkAccessManager PUT method delete Json data over server:

          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?

          Like @SGaist said, you must ask your server why.

          Most servers that I know don't delete data when the client doesn't provide a header.

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          1

          3/4

          28 Jun 2019, 06:42

          • Login

          • Login or register to search.
          3 out of 4
          • First post
            3/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved