CURL操作

GET请求

无参数请求

  1. use Timo\Curl;
  2. $url = 'http://www.timophp.com/';
  3. $res = Curl::get($url);
  4. var_dump($res);

有参数请求

  1. use Timo\Curl;
  2. $url = 'http://www.timophp.com/user/info/';
  3. $app_id = '1000000189';
  4. $app_secret = 'O35LGESDF454KIPN67DZX';
  5. $user_id = 1000001;
  6. $timestamp = time();
  7. $vars = array(
  8. 'app_id' => $app_id,
  9. 'user_id' => $user_id,
  10. 'timestamp' => $timestamp,
  11. 'sign' => md5($app_id . $user_id . $timestamp . $app_secret);
  12. );
  13. Curl::get($url, $vars);

POST请求

  1. use Timo\Curl;
  2. $url = 'http://api.timophp.com/user/register/';
  3. $app_id = '1000000189';
  4. $app_secret = 'O35LGESDF454KIPN67DZX';
  5. $user_name = 'timophp';
  6. $timestamp = time();
  7. $vars = array(
  8. 'app_id' => $app_id,
  9. 'user_name' => $user_name,
  10. 'timestamp' => $timestamp,
  11. 'sign' => md5($app_id . $user_id . $timestamp . $app_secret);
  12. );
  13. Curl::post($url, $vars);

设置请求超时时间

第三个参数设置请求超时时间

  1. Curl::get($url, $vars, 10);
  2. 设置超时时间为10秒钟

第四个参数设置代理

  1. use Timo\Curl;
  2. $proxy = "http://180.169.37.66:8090";
  3. $res = Curl::get($url, $vars, 10, $proxy);