Similar to host service providers such as dreamhost, it shows the use of fopen. Php curl supports FTP, FTPS, HTTPHTPPSSCPSFTPTFTPTELNETDICTFILE, and LDAP. Curl supports SSL certificates, http post, http put, and FTP uploads, 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 );