In php, the curl function can implement get and post operations. we often use it for some human imitation operations. below I will briefly introduce the post and get examples. get method, the code is as follows: $ urlqu... in php, the curl function can implement get and post operations. we often use it for some human imitation operations. below I will briefly introduce the post and get examples.
The code for the get method is as follows:
$ Url = "http://www.phprm.com/index. php? A = B & c = d & e = f & g = ". urlencode ('Wang Lu's blog '); $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 ); // the result must be a string and be output to curl_setopt ($ ch, CURLOPT_HEADER, 0) on the screen; // do not use http header to accelerate the efficiency of curl_setopt ($ ch, CURLOPT_USERAGENT, 'mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0) '); curl_setopt ($ ch, CURLOPT_TIMEOUT, 15); $ output = curl_exec ($ ch ); curl_close ($ ch); var_dump ($ output );
Post method, the code is as follows:
$ Url = "http://www.phprm.com/index.php"; $ params = "a = B & c = d & e = f & g = ". urlencode ('Wang Lu's blog '); $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 ); // the result must be a string and be output to curl_setopt ($ ch, CURLOPT_HEADER, 0) on the screen; // do not use http header to accelerate the efficiency of curl_setopt ($ ch, CURLOPT_USERAGENT, 'mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0) '); curl_setopt ($ ch, CURLOPT_TIMEOUT, 15); // open source code phprm.com curl_setopt ($ ch, CURLOPT_POST, 1); // curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ params); $ output = curl_exec ($ ch); curl_close ($ ch); var_dump ($ output );
When requesting https data, the certificate is required. at this time, add the following two parameters to avoid ssl certificate check. the code is as follows:
Curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https requests do not verify the certificate and hosts. curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, FALSE );
Permanent link:
Reprint at will! Include the article address.