function http( $url, $method = 'GET', array $postfields = array(), array $headers = array() ){
$ci = curl_init();
/* Curl settings */
curl_setopt( $ci, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0 );
curl_setopt( $ci, CURLOPT_CONNECTTIMEOUT, 30 );
curl_setopt( $ci, CURLOPT_TIMEOUT, 30 );
curl_setopt( $ci, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ci, CURLOPT_ENCODING, 'gzip' );
curl_setopt( $ci, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ci, CURLOPT_MAXREDIRS, 5 );
curl_setopt( $ci, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ci, CURLOPT_HEADER, false );
switch( strtoupper( $method ) )
{
case 'POST':
curl_setopt( $ci, CURLOPT_POST, true );
if ( !empty( $postfields ) )
{
curl_setopt( $ci, CURLOPT_POSTFIELDS, http_build_query( $postfields ) );
}
break;
case 'DELETE':
curl_setopt( $ci, CURLOPT_CUSTOMREQUEST, 'DELETE' );
if ( !empty( $postfields ) )
{
$url = "{$url}?" . http_build_query( $postfields );
}
break;
case 'GET':
if ( !empty( $postfields ) )
{
$url = "{$url}?" . http_build_query( $postfields );
}
break;
}
curl_setopt($ci, CURLOPT_URL, $url );
curl_setopt($ci, CURLOPT_HTTPHEADER, $headers );
curl_setopt($ci, CURLINFO_HEADER_OUT, true );
$response = curl_exec( $ci );
curl_close ($ci);
return $response;
}