本文实例讲述了php使用curl通过代理获取数据的实现方法。分享给大家供大家参考,具体如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
$curl =curl_init(); curl_setopt( $curl , CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:20.0) Gecko/20100101 Firefox/20.0' ); curl_setopt( $curl , CURLOPT_POST, true); curl_setopt( $curl , CURLOPT_POSTFIELDS, http_build_query( $param )); curl_setopt( $curl , CURLOPT_RETURNTRANSFER, true); curl_setopt( $curl , CURLOPT_HTTPPROXYTUNNEL, true); curl_setopt( $curl , CURLOPT_PROXYAUTH, CURLAUTH_BASIC); curl_setopt( $curl , CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); curl_setopt( $curl , CURLOPT_PROXY, "180.186.11.121" ); curl_setopt( $curl , CURLOPT_PROXYPORT, "37211" ); curl_setopt( $curl , CURLOPT_PROXYUSERPWD, "taras:taras-ss5" ); $result =curl_exec( $curl ); |
PS:小编在这里推荐一款本站的php格式化美化的排版工具帮助大家在以后的PHP程序设计中进行代码排版:
php代码在线格式化美化工具:http://tools.jb51.net/code/phpformat