Php curl implements get and post code. Curl supports uploading SSL certificates, HTTPPOST, HTTPPUT, and FTP, kerberos, HTT-based Upload, proxy, cookie, user + password proof, file transfer recovery, http proxy channel, curl support SSL certificate, http post, http put, FTP upload, kerberos, HTT-based Upload, proxy, cookie, user + password proof, file transfer recovery, and http proxy channel are the most common methods based on http get and post.
Code implementation:
1. http get implementation
The code is as follows:
$ Ch = curl_init ("http://www.jb51.net /");
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true );
Curl_setopt ($ ch, CURLOPT_BINARYTRANSFER, true );
$ Output = curl_exec ($ ch );
$ Fh = fopen ("out.html", 'w ');
Fwrite ($ fh, $ output );
Fclose ($ fh );
2. http post implementation
The code is as follows:
// Extract data from the post
Extract ($ _ POST );
// Set POST variables
$ Url = 'http: // www.jb51.net/get-post.php ';
$ Fields = array (
'Lname' => urlencode ($ last_name ),
'Fname' => urlencode ($ first_name ),
'Title' => urlencode ($ title ),
'Company' => urlencode ($ institution ),
'Age' => urlencode ($ age ),
'Email '=> urlencode ($ email ),
'Phone' => urlencode ($ phone)
);
// Url-ify the data for the POST
Foreach ($ fields as $ key => $ value) {$ fields_string. = $ key. '='. $ value .'&';}
Rtrim ($ fields_string ,'&');
// Open connection
$ Ch = curl_init ();
// Set the url, number of POST vars, POST data
Curl_setopt ($ ch, CURLOPT_URL, $ url );
Curl_setopt ($ ch, CURLOPT_POST, count ($ fields ));
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ fields_string );
// Execute post
$ Result = curl_exec ($ ch );
// Close connection
Curl_close ($ ch );
Http://www.bkjia.com/PHPjc/319274.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/319274.htmlTechArticlecurl supports SSL certificates, http post, http put, FTP uploads, kerberos, HTT-based Upload, proxy, cookie, user + password proof, file transfer recovery, http proxy channel is the most...