I am posting form data to a curl script which is received by curl properly but curl is not posting that data to api and null data is returned.
I want the data to be posted to api and return json data,which i will display on screen.
- $url = “https://myapiurl.com/”;
- $userid = $_POST[‘clientid’];
- $token = $_POST[‘apikey’];
- $headers = array(
-
'Method: GET',
-
'Authorization: Basic '. base64_encode($userid.':'.$token)
-
);
- $curl = curl_init();
- $fields = array(
-
'panchangdate' => $_POST["panchangdate"],
-
'panchanglongitude' => $_POST["panchanglongitude"],
-
'panchanglatitude' => $_POST["panchanglatitude"],
-
'panchangtimezone' => $_POST["panchangtimezone"]
- );
- $fields_string = http_build_query($fields);
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_POST, TRUE);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
- curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $fields_string);
- curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
- $response = curl_exec($curl);
- $err = curl_error($curl);
- curl_close($curl);
- if ($err) {
- echo “cURL Error #:” . $err;
- else {
- //echo $response;
- /*
- echo “
";
- echo json_encode(json_decode($response), JSON_PRETTY_PRINT);
- echo “”;
- */
- $data = json_decode($response);
- ?>