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

QNetworkAccessManager PUT method delete Json data over server

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 632 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 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
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on 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 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

        JKSHJ 1 Reply Last reply
        0
        • N npatil15

          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

          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on 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

          • Login

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