title: PHP cURL, POST JSON
body: <p>I need to POST the following JSON code, but for some reason it is not working. Below is the code that I have.</p>
  
  <pre><code>$fieldString = "395609399";
  //the curl request processor
  function processCurlJsonrequest($URL, $fieldString) { //Initiate cURL request and send back the result
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_HTTPHEADERS, array('Content-Type: application/json'));
      curl_setopt($ch, CURLOPT_URL, $URL);
      curl_setopt($ch, CURLOPT_USERAGENT, $this-&gt;_agent);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
      curl_setopt($ch, CURLOPT_COOKIEFILE, $this-&gt;_cookie_file_path);
      curl_setopt($ch, CURLOPT_COOKIEJAR, $this-&gt;_cookie_file_path);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
      curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
      if ($fieldCount) { // in case of post fields present then pass it on
          curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode("{categoryId: $fieldString}"));
          curl_setopt($ch, CURLOPT_POST, 1);
      }
      $resulta = curl_exec($ch);
      if (curl_errno($ch)) {
          print curl_error($ch);
      } else {
          curl_close($ch);
      }
      return $resulta;
  }
  </code></pre>
  
  <p>Here is the function which calls the cURL request:</p>
  
  <pre><code>function get_cat($categoryId, $URL) {
      $fields = array(
          "categoryId" =&gt; $categoryId
      );
      $fields_string = $fields;
      return $this-&gt;processCurlJsonrequest($URL, $fields_string);
  }
  </code></pre>