<?php
$ch = curl_init();
$client_id="clientID";
$client_secret="clientSecret";
$language="python3";
$versionIndex="0";
$script=(string)$_POST["script"];
$data="{
\"clientId\": \"$client_id\",
\"clientSecret\":\"$client_secret\",
\"script\":\"$script\",
\"language\":\"$language\",
\"versionIndex\":\"0\"
}";
echo $data;
curl_setopt($ch, CURLOPT_URL, "https://api.jdoodle.com/v1/execute");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = "Content-Type: application/json; charset=UTF-8";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
//echo $result;
$data = json_decode($result, TRUE);
print_r($data);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
?>
I tried to send the code as string to jdoodle api. I am getting invalid request as output. I think the problem is with $_POST variable. I am getting output when I am not using $_POST variable. so please solve this problem . Is there any other way to send data to an api. Thanks in advance for helping me