QNetworkAccessManager PUT method delete Json 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,
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?
-
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.
-
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
-
@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.