title: How to send a POST request in Qt with the JSON body
body: <p>I'm trying to send a POST request from Qt where the body is in JSON format. Firstly I'm asserting that the request works in curl:</p>
  <pre><code>curl -i -H &quot;Content-Type: application/json&quot; -d '{&quot;key1&quot;: &quot;value1&quot;, &quot;key2&quot;: &quot;value2&quot;}' -X POST http://myserver.com/api
  </code></pre>
  <p>That works OK, I'm receiving back the expected response from the server. The same works in Python. Now I need to send this request from C++/Qt:</p>
  <pre><code>QNetworkAccessManager *mgr = new QNetworkAccessManager(this);
  QHttpMultiPart *httpMultiPart = new QHttpMultiPart(mgr);
  QHttpPart *httpPart = new QHttpPart();
  httpPart-&gt;setHeader(QNetworkRequest::ContentTypeHeader, QVariant(&quot;application/json&quot;));
  httpPart-&gt;setBody(&quot;{\&quot;key1\&quot;:\&quot;value1\&quot;, \&quot;key2\&quot;:\&quot;value2\&quot;}&quot;);
  
  httpMultiPart-&gt;append(*httpPart);
  
  QNetworkReply *reply = mgr-&gt;post(QNetworkRequest(QUrl(&quot;http://myserver.com/api&quot;)), httpMultiPart);
  QObject::connect(reply, &amp;QNetworkReply::finished, [=]()
          {
              QString err = reply-&gt;errorString();
              QString contents = QString::fromUtf8(reply-&gt;readAll());
          });
  </code></pre>
  <p>Now I'm getting an error where the errorString returns: `</p>
  <pre><code>&quot;Error downloading http://myserver.com/api - server replied: Unsupported Media Type&quot;`
  </code></pre>
  <p>What can be the reason? How should I send the POST request like the one that I'm sending with curl?</p>