CURL操作

GET请求

public static function get($url, $data = [], $header = [], $expire = 30, $proxy = null)

无参数请求

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/';
$vars = [
    'uid' => 100,
    'timestamp' => time(),
];

Curl::get($url, $vars);

有请求头请求

use Timo\Curl;

$url = 'http://www.timophp.com/user/info/';
$vars = [
    'uid' => 100,
    'timestamp' => time(),
];
$headers = [
    'Token' => 'abc123'
];

Curl::get($url, $vars, $headers);

POST请求

use Timo\Curl;

$url = 'http://www.timophp.com/user/info/';
$vars = [
    'uid' => 100,
    'timestamp' => time(),
];

Curl::post($url, $vars);

有请求头请求

use Timo\Curl;

$url = 'http://www.timophp.com/user/info/';
$vars = [
    'uid' => 100,
    'timestamp' => time(),
];
$headers = [
    'Token' => 'abc123'
];

设置请求超时时间

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

use Timo\Curl;

$url = 'http://www.timophp.com/user/info/';
$vars = [
    'uid' => 100,
    'timestamp' => time(),
];

Curl::get($url, $vars, [], 10); //设置超时时间为10秒钟

第五个参数设置代理

use Timo\Curl;

$proxy = "http://180.169.37.66:8090";
$res = Curl::get($url, $vars, [], 10, $proxy);
var_dump($res);