title: RESTful API requests using Qt
body: <p>I'm trying to get example found from this <a href="https://www.creativepulse.gr/en/blog/2014/restful-api-requests-using-qt-cpp-for-linux-mac-osx-ms-windows" rel="noreferrer">link</a> to work.</p>
  
  <p><code>GET</code> and <code>DELETE</code> methods are working but I have some issue with <code>PUT</code> and <code>POST</code>. I get server replied: <strong>Bad Request</strong>. With <code>qDebug()</code> I get this error:</p>
  
  <blockquote>
    <p>QNetworkReply::NetworkError(ProtocolInvalidOperationError) </p>
  </blockquote>
  
  <p>To <strong>httprequestworker.cpp</strong>, I have changed request type to: </p>
  
  <pre><code>request_content.append("Content-Type: application/fhir+json");
  </code></pre>
  
  <p>Here is my function for getting contents of JSON file from computer and executing the whole input of request for the server:</p>
  
  <pre><code>void MainWindow::on_pushButton_clicked()
  {
      QString url_str = "http://hapi.fhir.org/baseDstu3/Patient/4705560";
  
      HttpRequestInput input(url_str, "PUT");
  
      QString settings;
      QFile file;
  
      file.setFileName("C:/Users/Lauri/Desktop/FHIR/Omia testeja/themostsimplepatientJSON.json");
      file.open(QIODevice::ReadOnly | QIODevice::Text);
      settings = file.readAll();
      file.close();
  
      settings.remove(QRegExp("[\\n]"));
      qDebug() &lt;&lt; settings;
      settings.toUtf8();
      input.add_var("key1", settings);
  
  
      HttpRequestWorker *worker = new HttpRequestWorker(this);
      connect(worker, SIGNAL(on_execution_finished(HttpRequestWorker*)), this, SLOT(handle_result(HttpRequestWorker*)));
      worker-&gt;execute(&amp;input);
  }
  </code></pre>
  
  <p>Here is the simple JSON I want to upload:</p>
  
  <pre><code>{
    "resourceType": "Patient",
    "text": {
      "status": "generated",
      "div": "&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;This is a test patient&lt;a name='mm'/&gt;&lt;/div&gt;"
    },
    "name": [
      {
        "use": "usual",
        "prefix": [
          "Mr"
        ],
        "given": [
          "Teppo",
          "Testi"
        ],
        "family": "Testinen"
      }
    ],
    "telecom": [
      {
        "value": "123456789",
        "system": "phone",
        "use": "home"
      }
    ],
    "gender": "male",
    "birthDate": "2018-08-21"
  }
  </code></pre>
  
  <p>JSON file should be right because I have been able to <code>POST</code> and <code>PUT</code> with postman and other tools. Is there something obvious that I'm missing?</p>
  
  <p>Captures from postman:</p>
  
  <p><img src="https://i.stack.imgur.com/qVBHd.png" alt="PUT Headers"></p>
  
  <p><img src="https://i.stack.imgur.com/Kd0p9.png" alt="PUT Body"></p>
  
  <p><a href="https://i.stack.imgur.com/ZAQpU.png" rel="noreferrer">POST Headers</a></p>
  
  <p><a href="https://i.stack.imgur.com/GKLIq.png" rel="noreferrer">POST Body</a></p>
  
  <p>With <code>qDebug()</code> I can see that reading JSON is successful. I have been trying to find solution for <code>ProtocolInvalidOperationError</code> with no success. </p>