使用PHP通过API提取链接获取代理IP的代码样例

温馨提示:
1. 以下样例分别为Guzzle、使用stream流、curl通过调用API提取链接获取代理IP
2. Guzzle是一个简单强大的http客户端库,需要安装才能使用:
安装composer curl -sS https://getcomposer.org/installer | php
安装Guzzle php composer.phar require guzzlehttp/guzzle:~6.0
3. API提取链接在控制台中"实例管理"中生成


Guzzle

request('GET', $api_url, [
	'headers' => [
		'Accept-Encoding' => 'gzip'  // 使用gzip压缩让数据传输更快
	]
]);


echo $res->getStatusCode(); //获取Reponse的返回码
echo "\n\n";
echo $res->getBody(); //获取API返回内容
?>

使用stream流


	array(
		'method'  => 'GET',
		'header'  => 'Accept-Encoding: gzip',  // 使用gzip压缩让数据传输更快
	)
);

$context = stream_context_create($opts);

$result = file_get_contents($api_url, false, $context);

echo gzdecode($result);  // 输出返回内容
?>

curl