function http($url, $method, $postfields = NULL){
$this->http_info = array();
$ci = curl_init();
/* Curl settings */
curl_setopt($ci, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent);
curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ci, CURLOPT_ENCODING, "");
curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
curl_setopt($ci, CURLOPT_HEADER, FALSE);
switch ($method){
case 'POST':
curl_setopt($ci, CURLOPT_POST, TRUE);
if(!empty($postfields)){
curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
$this->postdata = $postfields;
}
break;
case 'DELETE':
curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
if(!empty($postfields)){
$url = "{$url}?{$postfields}";
}
}
$headers=array();
if (isset($this->access_token) && $this->access_token){
$headers[] = "Authorization: OAuth2 ".$this->access_token;
}
if($this->username && $this->password){
curl_setopt($ci, CURLOPT_USERPWD, $this->username . ':' . $this->password);
}
if(isset($_SERVER['REMOTE_ADDR']))
{
$headers[] = "API-RemoteIP: ".$_SERVER['REMOTE_ADDR'];
}
curl_setopt($ci, CURLOPT_URL, $url);
if(false==empty($headers))
{
curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);
}
curl_setopt($ci, CURLINFO_HEADER_OUT, TRUE);
$response = curl_exec($ci);
$this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
$this->http_info = array_merge($this->http_info, curl_getinfo($ci));
$this->url = $url;
if($this->debug){
echo "=====post data======\r\n";
var_dump($postfields);
echo '=====info====='."\r\n";
print_r( curl_getinfo($ci) );
echo '=====$response====='."\r\n";
print_r( $response );
}
curl_close ($ci);
return $response;
}