This article is mainly to share with you in PHP, the way Curl Crawl Web response data, I hope to help everyone.
<?phpnamespace app\index\model;use think\model;class HttpPost extends model{/** * POST request Fetch data * @param string $url * @param array $param * @return string content */public function HttpPost ($url, $param, $cookie _file) {$oCurl = Curl_init (); if (Stripos ($url, "https://")!== FALSE) {curl_setopt ($oCurl, Curlopt_ssl_verifypeer, false); curl_setopt ($oCurl, Curlopt_ssl_verifyhost, false); } if (Is_string ($param)) {$strPOST = $param; } else {$aPOST = array (); foreach ($param as $key = = $val) {$aPOST [] = $key. "=" . UrlEncode ($val); } $strPOST = Join ("&", $aPOST); } curl_setopt ($oCurl, Curlopt_url, $url); curl_setopt ($oCurl, Curlopt_returntransfer, 1); curl_setopt ($oCurl, Curlopt_post, true); curl_setopt ($oCurl, Curlopt_postfields, $strPOST); curl_setopt ($oCurl, Curlopt_ssl_verifypeer, false);//filter htpts//curl_setopt ($oCurl, Curlopt_ssl_verifyhost, False) ;//Filter htpts $UserAgent = ' mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1;. NET CLR 2.0.50727;. NET CLR 3.0.04506;. NET CLR 3.5.21022;. NET CLR 1.0.3705;. NET CLR 1.1.4322) ';//curl_setopt ($ Ocurl, Curlopt_useragent, $UserAgent); Use proxy//////curl_setopt ($oCurl, Curlopt_header, false);//curl_setopt ($oCurl, Curlopt_header, 0); curl_setopt ($oCurl, Curlopt_cookiefile, $cookie _file); $sContent = curl_exec ($oCurl); $aStatus = Curl_getinfo ($oCurl); Curl_close ($oCurl); if (Intval ($aStatus ["http_code"] = =) {return $sContent; } else {return false; }}}