<?php



function HTTPPost($url, $data, $headers=array()) {

    $ch = curl_init();

    //set the url, number of POST vars, POST data
    curl_setopt($ch,CURLOPT_URL, $url);
    curl_setopt($ch,CURLOPT_POST, true);
    curl_setopt($ch,CURLOPT_POSTFIELDS, $data);
    // curl_setopt ($ch, CURLOPT_CAINFO, "C:\\wamp\\cacert.pem");
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    // curl_setopt($ch,CURLOPT_, $data);

    //So that curl_exec returns the contents of the cURL; rather than echoing it
    curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); 

    
    //execute post
    $result = curl_exec($ch);
    $info = curl_getinfo($ch);

    $info["data"] = json_decode($result, true);
    

    $info["successful"] = ($info["http_code"] >= 200 && $info["http_code"] < 300);

    return $info;
    
}




function HTTPGet($url, $headers=array()) {

    $ch = curl_init();

    //set the url, number of POST vars, POST data
    curl_setopt($ch,CURLOPT_URL, $url);
    // curl_setopt ($ch, CURLOPT_CAINFO, "C:\\wamp\\cacert.pem");
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    // curl_setopt($ch,CURLOPT_, $data);

    //So that curl_exec returns the contents of the cURL; rather than echoing it
    curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); 

    
    //execute post
    $result = curl_exec($ch);
    $info = curl_getinfo($ch);

    $info["data"] = json_decode($result, true);
    

    $info["successful"] = ($info["http_code"] >= 200 && $info["http_code"] < 300);

    return $info;   
}

