Following PHP cURL code can be used to connect and get the response of Panchang API.
<?php
//debug
error_reporting(E_ALL);
ini_set('display_errors', 1);
//debug end
$url = "https://panchangb.jyotishapi.com";
$userid = 'client_id';
$token = 'client_token';
$headers = array(
'Method: GET',
'Authorization: Basic '. base64_encode($userid.':'.$token)
);
$curl = curl_init();
$fields = array(
'panchangdate' => $_POST["panchangdate"],
'panchangtime' => $_POST["panchangtime"],
'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);
//curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
$data = json_decode($response);