Skip to content

Instantly share code, notes, and snippets.

@ciaranmg
Created January 8, 2014 18:46
Show Gist options
  • Save ciaranmg/8322096 to your computer and use it in GitHub Desktop.
Save ciaranmg/8322096 to your computer and use it in GitHub Desktop.
HTTP Request Method
function httpRequest($req,$hash_config=NULL){
$config = Obj2xml::getConfig($hash_config);
$ch = curl_init();
if($config['proxy'] !== ''){
curl_setopt($ch, CURLOPT_PROXY, $config['proxy']);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, true);
}
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: text/xml'));
curl_setopt($ch, CURLOPT_URL, $config['url']);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_TIMEOUT, $config['timeout']);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// curl_setopt($ch, CURLOPT_CAINFO, "/home/cmcgrath/litle_CA.pem");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
$output = curl_exec($ch);
$responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (! $output){
throw new Exception (curl_error($ch));
}
else
{
curl_close($ch);
return $output;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment