Curl Crawl Web response data in PHP

Source: Internet
Author: User
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; }}}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

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.