public function run() {
// $response = $this->httpClient->request('GET', 'https://plugin.newmorehot.com/v2/index/ip', [
// 'proxy' => '代理IP:代理端口',
// 'curl' => [
// CURLOPT_PROXYUSERPWD => '用户名:密码'
// ]
// ]);
$response = $this->httpClient->request('GET', 'https://plugin.newmorehot.com/v2/index/ip', [
'proxy' => '127.0.0.1:10809',
'curl' => [
CURLOPT_PROXYUSERPWD => 'user:123456'
]
]);
$code = $response->getStatusCode(); // 200
$reason = $response->getReasonPhrase(); // OK
// print_r(array(
// 'code' => $code,
// 'reason' => $reason
// ));
if ($code != 200 && $reason != 'OK') {
return false;
}
$bodyContents = $response->getBody()->getContents();
print_r($bodyContents);
}
curl原生案例
$url = 'http://dynupdate.no-ip.com/ip.php';
$proxy = '127.0.0.1:8888';
//$proxyauth = 'user:password';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
//curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);
echo $curl_scraped_page;
参考资料