Use the curl module in php to implement http get and post methods. The php curl can support FTP, FTPS, HTTPHTPPSSCPSFTPTFTPTELNETDICTFILE, and use the curl module in php to implement http get and post methods, php curl supports FTP, FTPS, http htpps scp sftp tftp telnet dict file 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
$ Ch = curl_init ("/"); 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
// Extract data from the post Extract ($ _ POST ); // Set POST variables $ Url = '/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 ); ?> |