PHP example of a call to getAllBooks
$sesskey = "xxxx"; // Your API key here
$params = array(
"version" => "6.20b",
"req" => "getAllBooks",
"o_u" => "demo",
"u_c" => "demo",
"sesskey" => $sesskey
);
$url = "https://timetonic.com/live/api.php";
$result = httpsPost($url,$params,true);
echo "api_response: $result\n";
function httpsPost($url, $params=[], $sync=false)
{
$post_params = array();
foreach ($params as $key => &$val) {
if (is_array($val))
$val = implode(',', $val);
$post_params[] = $key.'='.urlencode($val);
}
$queryString = implode('&', $post_params);
$parts=parse_url($url);
$path = $parts['path'];
$host = $parts['host'];
$fp = fsockopen("ssl://".$host,443,$errno, $errstr, 30);
fputs($fp, "POST $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ".strlen($queryString)."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $queryString . "\r\n\r\n");
$response = "";
if ($sync) {
while (!feof($fp)) {
$response .= fgets($fp, 128);
}
}
fclose($fp);
return $response;
}
Comments
0 comments
Please sign in to leave a comment.