CURL操作
GET请求
无参数请求
use Timo\Curl;
$url = 'http://www.timophp.com/';
$res = Curl::get($url);
var_dump($res);
有参数请求
use Timo\Curl;
$url = 'http://www.timophp.com/user/info/';
$app_id = '1000000189';
$app_secret = 'O35LGESDF454KIPN67DZX';
$user_id = 1000001;
$timestamp = time();
$vars = array(
'app_id' => $app_id,
'user_id' => $user_id,
'timestamp' => $timestamp,
'sign' => md5($app_id . $user_id . $timestamp . $app_secret);
);
Curl::get($url, $vars);
POST请求
use Timo\Curl;
$url = 'http://api.timophp.com/user/register/';
$app_id = '1000000189';
$app_secret = 'O35LGESDF454KIPN67DZX';
$user_name = 'timophp';
$timestamp = time();
$vars = array(
'app_id' => $app_id,
'user_name' => $user_name,
'timestamp' => $timestamp,
'sign' => md5($app_id . $user_id . $timestamp . $app_secret);
);
Curl::post($url, $vars);
设置请求超时时间
第三个参数设置请求超时时间
Curl::get($url, $vars, 10);
设置超时时间为10秒钟
第四个参数设置代理
use Timo\Curl;
$proxy = "http://180.169.37.66:8090";
$res = Curl::get($url, $vars, 10, $proxy);