title: cURL post request method
body: <p>Hello I have a problem with my cURL post request method. I need to get a content from an other host, so I got this method from <a href="http://php.net/manual/de/book.curl.php" rel="nofollow noreferrer">http://php.net/manual/de/book.curl.php</a> because I know that the destination host also uses cURL and gives a request to a service that executes an executable(exe).</p>
  
  <pre><code>    function postRequest($url, $data, $refer = "", $timeout = 10, $header = [])
  {
      $curlObj = curl_init();
      $ssl = stripos($url,'https://') === 0 ? true : false;
      $options = [
          CURLOPT_URL =&gt; $url,
          CURLOPT_RETURNTRANSFER =&gt; 1,
          CURLOPT_POST =&gt; 1,
          CURLOPT_POSTFIELDS =&gt; $data,
          CURLOPT_FOLLOWLOCATION =&gt; 1,
          CURLOPT_AUTOREFERER =&gt; 1,
          CURLOPT_USERAGENT =&gt; 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)',
          CURLOPT_TIMEOUT =&gt; $timeout,
          CURLOPT_HTTP_VERSION =&gt; CURL_HTTP_VERSION_1_0,
          CURLOPT_HTTPHEADER =&gt; ['Expect:'],
          CURLOPT_IPRESOLVE =&gt; CURL_IPRESOLVE_V4,
          CURLOPT_REFERER =&gt; $refer
      ];
      if (!empty($header)) {
          $options[CURLOPT_HTTPHEADER] = $header;
      }
      if ($refer) {
          $options[CURLOPT_REFERER] = $refer;
      }
      if ($ssl) {
          //support https
          $options[CURLOPT_SSL_VERIFYHOST] = false;
          $options[CURLOPT_SSL_VERIFYPEER] = false;
      }
      curl_setopt_array($curlObj, $options);
      $returnData = curl_exec($curlObj);
      if (curl_errno($curlObj)) {
          //error message
          $returnData = curl_error($curlObj);
      }
      curl_close($curlObj);
      return $returnData;
  }
  </code></pre>
  
  <p>I call the method like this:</p>
  
  <pre><code>$command= array();
  
   $command["cmd"] = "D://Workspace/Interne_Entwicklung/Folder1/Folder2/Executable.exe " . "--command " . chr(34) .
                      "[{'filters': [ {'Z_RG_Generiert':0} ],auth:[{'userid':'gartner'}],'RequestId': 105.1,'Status': 0}]" . chr(34);
   echo postRequest("localhost:8080",$command);
  </code></pre>
  
  <p>and it returns me an <strong>error</strong> <strong>("HTTP Error 411. The request must be chunked or have a content length.")</strong>
  I already tried to add an option to the option array that defines the Content-Length to the <code>CURLOPT_HTTPHEADER</code> option like this:</p>
  
  <pre><code>$command= array();
  
   $command["cmd"] = "D://Workspace/Interne_Entwicklung/PreisigTest2/PreisigTest2/bin/Debug/PreisigTest2.exe " . "--command " . chr(34) .
                      "[{'filters': [ {'Z_RG_Generiert':0} ],auth:[{'userid':'gartner'}],'RequestId': 105.1,'Status': 0}]" . chr(34);
   $header=array();
   $header['Content-Length'] = strlen(json_encode($command));
   echo postRequest("localhost:8080",json_encode($command),"",10,$header)
  </code></pre>
  
  <p>So my question is:</p>
  
  <ul>
  <li>What is the reason for this message?</li>
  <li>How can I solve it, with defining a content-length or is there another way? </li>
  </ul>