Please don't close this question before read my actual problem. I have seen many related problems but I am still having.
Simply I want to send a json_encoded array by POST method using CURL in PHP. When I set content-type as application/json the data is not posted. I receive empty post array. When I remove content-type line the data is posted but not as json.
Here is my code
$data = array('id' => $post['id'], 'action' => $post['action']);
$post_data = http_build_query($data);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_data));
I this case I receive empty post. If I comment out the line curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); I will receive the post data but not json encoded. I want json_encoded array. Will any one tell me what am I doing wrong?
Best Regards: