curl常用功能

來源:互聯網
上載者:User

標籤:數組   調試   釋放   相關   讀取   length   ica   span   調用   

 1 <?php  2  //建立一個新cURL資源 3 $ch = curl_init(); 4 //************************************************************************************ 5 //設定URL和相應的選項 6    //設定 HTTP 頭欄位的數組。格式: array(‘Content-type: text/plain‘, ‘Content-length: 100‘)  7  $headers  = array( 8 "content-type: application/x-www-form-urlencoded; charset=gb2312"); 9 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);10 curl_setopt($ch, CURLOPT_URL, "http://www.baidu.com/");11 //************************************************************************************12 //索要上傳的資料 注意:要傳送檔案時,要在檔案名稱前面加上  @  首碼並使用完整路徑13 $data = array(‘name‘=>‘beauty‘, "upload"=>"@a.zip");14 curl_setopt($ch, CURLOPT_POST, 1);15 curl_setopt($ch, CURLOPT_POSTFIELDS, $data);16 //************************************************************************************17 ////設定curl參數,要求結果是否輸出到螢幕上,為1的時候是不返回到網頁中,0:直接顯示 假設的0換成1的話,那麼接下來的$data就需要echo一下。18 curl_setopt($ch, CURLOPT_RETURNTRANSFER,0);//是否自動顯示返回的資訊 19 //是否顯示返回的http頭資訊20 curl_setopt($ch, CURLOPT_HEADER, 1);21 //************************************************************************************22 23 // 串連結束後,比如,調用 curl_close 後,儲存 cookie 資訊的檔案。  24 curl_setopt($ch,CURLOPT_COOKIEJAR, dirname(__FILE__).‘/cookie.txt‘); 25 //************************************************************************************26 //************************************************************************************27 28 curl_setopt($curl, CURLOPT_POST, 1);//post方式提交 29  curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));//要提交的資訊 30 //************************************************************************************31  32  //允許 cURL 函數執行的最長秒數。 33  curl_setopt($ch, CURLOPT_TIMEOUT, 10);34 //************************************************************************************35  36  curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__).‘/cookie.txt‘); //讀取cookie37 //************************************************************************************38 39 //curl_getinfo()函數返回cURL執行後這一請求相關的資訊,這對調試和排錯很有用: 取得對方響應後的資訊40 $info = curl_getinfo($ch);41 //************************************************************************************42 43 // 抓取URL並把它傳遞給瀏覽器44 $res = curl_exec($ch);45 46 // 關閉cURL資源,並且釋放系統資源47 curl_close($ch);48     echo "<pre>";49        print_r($info);50     echo "</pre>";51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72  ?>

 

curl常用功能

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.