PHP cURL, POST JSON

The bit that is the problem is:

curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode("{categoryId: $fieldString}"));

CURLOPT_POSTFIELDS will accept either an array of parameters, or a URL-encoded string of parameters:

curl_setopt($ch, CURLOPT_POSTFIELDS, array('json'=>json_encode($stuff)));
curl_setopt($ch, CURLOPT_POSTFIELDS, 'json='.urlencode(json_encode($stuff)));

Where json will be the name of the POST field (i.e.: will result in $_POST['json'] being accessible).

Leave a Comment