private function _connect($url, $header, $request, $postdata = false, $destination = false)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ) ;
curl_setopt($ch, CURLOPT_SSLVERSION, 1); // Require TLS
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, __DIR__."/certs/trusted-certs.crt");
curl_setopt($ch, CURLOPT_CAPATH, __DIR__."/certs/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request);
curl_setopt($ch, CURLOPT_HTTPHEADER, explode(self::LINE_END, $header));
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
if(is_array($postdata))
{
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
}
$response = curl_exec($ch);
if(self::DEBUG)
{
error_log(print_r(curl_getinfo($ch), true));
error_log($response);
}
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
//If this is a content request write the file
if($destination !== false)
{
//If the response was good then write
//the file and return true
if($code == '200')
{
$fh = fopen($destination, 'w');
fwrite($fh, $response);
if($fh !== false)
{
fclose($fh);
return true;
}
}
//The response was bad or the file couldn't
//be written so return false.
return false;
}
else return $response;
}