Portfree Production Program PHP's curl implementation get and post code

Source: Internet
Author: User
Curl supports SSL certificates, HTTP POST, http PUT, FTP uploads, Kerberos, HTT-based uploads, proxies, cookies, user + password proofs, file transfer recovery, HTTP proxy channels for the most common use, is an HTTP-based get and post method.
Code implementation:
1. Get implementation of HTTP

Copy the Code code 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, the HTTP POST implementation

Copy the Code code 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);

The above describes the Portfree production program PHP's curl implementation of get and post code, including Portfree production program aspects of the content, I hope the PHP tutorial interested in a friend helpful.

  • 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: info-contact@alibabacloud.com 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.