curl發送請求時攜帶cookie-轉載未驗證

來源:互聯網
上載者:User

標籤:ams   window   verify   har   article   client   構造   host   contents   

 1 <?php   2 header(‘Content-Type:text/html;charset=utf-8‘);   3 echo  "<pre>";   4    5 function curl($cookie,$user_agent,$destURL, $paramStr=‘‘,$flag=‘get‘,$ip=‘10.57.22.151‘,$fromurl=‘http://www.baidu.com‘){   6     $curl = curl_init();   7     if($flag==‘post‘){//post傳遞   8         curl_setopt($curl, CURLOPT_POST, 1);   9         curl_setopt($curl, CURLOPT_POSTFIELDS, $paramStr);  10     }  11     curl_setopt($curl, CURLOPT_URL, $destURL);//地址  12       13     curl_setopt($curl, CURLOPT_HTTPHEADER, array(‘X-FORWARDED-FOR:‘.$ip, ‘CLIENT-IP:‘.$ip));  //構造IP  14       15       16     curl_setopt($curl, CURLOPT_REFERER, $fromurl);  17     curl_setopt($curl, CURLOPT_TIMEOUT, 10);#10s逾時時間  18       19     curl_setopt ($curl, CURLOPT_USERAGENT, $user_agent);  20     //curl_setopt ($curl, CURLOPT_COOKIEJAR, $cookie);  21     curl_setopt ($curl, CURLOPT_COOKIEFILE, $cookie);  22       23     curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);  24     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);  25     $str = curl_exec($curl);  26     curl_close($curl);  27     return $str;  28 }  29   30       31     $postdata = ‘a=11111111111‘;  32     $user_agent = "Mozilla/5.".rand(0,100)." (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0";  33     $cookie = ‘d:\cookie.txt‘;  34     $getip=‘66.66.‘.rand(0,16).‘.‘.rand(0,158) ;  35     //file_put_contents(‘d:\cookie.txt‘, ‘‘);  36     $cookie_file = dirname(__FILE__).‘/cookie.txt‘;  37     ob_start();  38     $html =  curl($cookie_file,$user_agent,‘http://127.0.0.50/b.php‘,$postdata,‘post‘,$getip,‘‘);  39     ob_end_clean();  40       41     echo $html; 

cookie檔案

 1 127.0.0.50 FALSE / FALSE 1418875953 aaaa cccc  

 

 

轉載地址:

http://blog.csdn.net/ebw123/article/details/41980239

 

curl發送請求時攜帶cookie-轉載未驗證

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.