標籤: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