PHP curl靜默訪問遠程url

來源:互聯網
上載者:User

標籤:style   blog   http   io   color   os   ar   使用   sp   

PHP CURL操作詳解:

function send($url, $post_data = ‘‘, $method = ‘POST‘, $timeout = 3) {    $ch = curl_init();//初始化一個新的curl會話,返回一個cURL控制代碼. //控制代碼:在程式設計中,控制代碼是一種特殊的智能指標 。當一個應用程式要引用其他系統(如資料庫、作業系統)所管理的記憶體塊或對象時,就要使用控制代碼。    curl_setopt($ch, CURLOPT_URL, $url); // 需要擷取的URL地址     curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) \r\n Accept: */*‘));//header頭    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);//請求逾時時間,為了防止資源被長期佔有    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//是否接收請求返回的資料 1接收 2不接受    if ($method == ‘POST‘)        curl_setopt($ch, CURLOPT_POST, 1);//post方式向遠程URL傳遞參數 1開啟post請求 0不開啟    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);    $content = curl_exec($ch);//接收請求返回的資料    $response = curl_getinfo($ch);//請求的詳細資料 curl_close($ch);//關閉CURL控制代碼 return $content;} 

 

PHP curl靜默訪問遠程url

聯繫我們

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