【NB】PHP常见方法封装
快进来[滑稽]http://cdn.u1.huluxia.com/g4/M03/81/36/rBAAdmL-83OAVsFJAAO4_BHsxHw038.jpg
GET请求
function get_curl($url, $timeout = 5) {
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true );
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
$result = curl_exec( $ch );
curl_close($ch);
return $result;
}
POST请求
function post_curl($url, $data, $timeout = 5) {
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true );
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
$result = curl_exec( $ch );
curl_close($ch);
return $result;
}
页:
[1]