PHP中使用curl及代理IP模拟post提交【两种实用方法】
2014-08-18 09:13
1211 查看
方法一:
方法二:
function request_by_other($remote_server,$post_string){ $context = array( 'http'=>array( 'proxy'=>'127.0.0.1:8787', // 代理IP 'request_fulluri'=>true, // 是否使用代理 'method'=>'POST', 'header'=>'Content-type: application/x-www-form-urlencoded'."\r\n". 'User-Agent : Jimmy\'s POST Example beta'."\r\n". 'Content-length: '.strlen($post_string)+8, 'content'=>'article_id='.$post_string) ); $stream_context = stream_context_create($context); $data = @file_get_contents($remote_server,FALSE,$stream_context); return $data; } $remote_server = "http://www.xxxxx.com/article/yj/views.jhtml"; $post_string = "10898"; var_dump(request_by_other($remote_server, $post_string));
方法二:
function curl_string ($url,$user_agent,$proxy){ $ch = curl_init(); if (!empty($proxy)) { // 有代理IP就使用代理 curl_setopt ($ch, CURLOPT_PROXY, $proxy); // 使用代理IP // 伪造客户端来源IP $xforip = rand(1, 254).".".rand(1, 254).".".rand(1, 254).".".rand(1, 254); curl_setopt ($ch, CURLOPT_HTTPHEADER, array('CLIENT-IP:'.$xforip, 'X-FORWARDED-FOR:'.$xforip)); } curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_POSTFIELDS, 'article_id=10898'); curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent); //模拟用户使用的浏览器 curl_setopt ($ch, CURLOPT_COOKIEJAR, dirname(__FILE__)."\cookie.txt"); // curl_setopt ($ch, CURLOPT_HEADER, 1); //输出头信息 curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转 curl_setopt ($ch, CURLOPT_AUTOREFERER, 1 ); // 自动设置Referer curl_setopt ($ch, CURLOPT_TIMEOUT, 120); $result = curl_exec ($ch); curl_close($ch); return $result; } $url_page = "http://www.xxxxxx.com/article/yj/views.jhtml"; $user_agentArray = array( "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36", ); $proxyArray = array( "http://125.39.68.180:80", "http://111.206.81.248:80", ); $proxy = empty($proxyArray) ? "" : $proxyArray[rand(0, count($proxyArray) - 1)]; $user_agent = $user_agentArray[rand(0, count($user_agentArray) - 1)]; var_dump(curl_string($url_page,$user_agent, $proxy));
相关文章推荐
- PHP中使用curl及代理IP模拟post提交【两种实用方法】
- PHP中使用curl及代理IP模拟post提交【两种实用方法】
- PHP模拟POST提交数据并获得返回值之CURL方法(使用PHP extension,然后使用php_curl.dll,很不错)
- Java中使用多线程、curl及代理IP模拟post提交和get访问
- Java中使用多线程、curl及代理IP模拟post提交和get访问
- Java中使用多线程、curl及代理IP模拟post提交和get访问
- php使用CURL模拟GET与POST向微信接口提交及获取数据的方法
- Java中使用多线程、curl及代理IP模拟post提交和get訪问
- Java中使用多线程、curl及代理IP模拟post提交和get访问
- php中使用Curl、socket、file_get_contents三种方法POST提交数据
- php 使用curl模拟ip和来源进行访问的实现方法
- php中使用Curl、socket、file_get_contents三种方法POST提交数据
- php中使用Curl、socket、file_get_contents三种方法POST提交数据
- PHP模拟POST提交的2种方法 curl,fsockopen,HttpClient
- PHP使用curl模拟post上传及接收文件的方法
- php中使用Curl、socket、file_get_contents三种方法POST提交数据
- PHP利用CURL方法模拟POST提交数据并获得返回值的小细节
- PHP使用curl模拟post上传及接收文件的方法
- php中模拟POST提交数据两种方法
- php中模拟POST提交数据两种方法