Php uses the curl function to obtain https webpage and post data samples

Source: Internet
Author: User
Functionvpost ($ url, $ data) {function for simulating data submission $ curlcurl_init (); starts a CURL session
Function vpost ($ url, $ data) {// simulate the data submission function $ curl = curl_init (); // Start a CURL session curl_setopt ($ curl, CURLOPT_URL, $ url ); // curl_setopt ($ curl, CURLOPT_SSL_VERIFYPEER, 0); // Check the certificate source curl_setopt ($ curl, CURLOPT_SSL_VERIFYHOST, 1 ); // check from the certificate whether the SSL encryption algorithm has curl_setopt ($ curl, CURLOPT_USERAGENT, $ _ SERVER ['http _ USER_AGENT ']); // simulate the user's browser curl_setopt ($ curl, CURLOPT_FOLLOWLOCATION, 1); // use automatic jump curl_setopt ($ curl, CURLOPT_AUTOREFERER, 1 ); // automatically set Referer curl_setopt ($ curl, CURLOPT_POST, 1); // send a regular Post request curl_setopt ($ curl, CURLOPT_POSTFIELDS, $ data ); // Post the submitted data packet curl_setopt ($ curl, CURLOPT_TIMEOUT, 30); // Set the timeout limit to prevent endless loops curl_setopt ($ curl, CURLOPT_HEADER, 0 ); // display the returned Header content curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1); // The obtained information returns $ tmpInfo = curl_exec ($ curl) as a file stream ); // execute the operation if (curl_errno ($ curl) {echo 'errno '. curl_error ($ curl); // catch an exception} curl_close ($ curl); // Close the CURL session return $ tmpInfo; // return data}

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.