Curl remote transmission tool-PHP source code

Source: Internet
Author: User
Curl remote transmission tool
/*** Curl remote transmission tool */public function post_curl ($ url, $ body, $ header, $ type = 'post') {$ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_HEADER, 0); // 0 as long as the body curl_setopt ($ ch, CURLOPT_TIMEOUT, 5 ); // Set the timeout value curl_setopt ($ ch, CURLOPT_CONNECTTIMEOUT, 5); // return the information obtained by curl_exec () in the form of a file stream instead of a direct output. Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); // add header information // array_push ($ header, 'Accept: application/json'); // array_push ($ header, 'content-Type: application/json'); // array_push ($ header, 'http: multipart/form-data'); if (count ($ body)> 0) {curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ body);} if (count ($ header)> 0) {curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ header );} // Set the curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, true); curl_set Opt ($ ch, CURLOPT_MAXREDIRS, 3); // recursive curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, false); // Check the certificate source curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, 0); // Check the SSL encryption algorithm switch ($ type) {case 'get': curl_setopt ($ ch, CURLOPT_HTTPGET, 1); break; case 'Post ': curl_setopt ($ ch, CURLOPT_POST, 1); break; case 'put': curl_setopt ($ ch, CURLOPT_CUSTOMREQUEST, 'put'); break; case 'delete ': curl_setopt ($ ch, CURLOPT_CUSTOMREQUEST, 'delete'); break ;} // Set curl_setopt ($ ch, CURLOPT_ENCODING, 'gzip '); curl_setopt ($ ch, CURLOPT_USERAGENT, 'ssts Browser/100'); curl_setopt ($ ch, CURLOPT_USERAGENT, 'mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0) '); // simulate the user's browser if (curl_errno ($ ch )) {return curl_error ($ ch) ;}$ content = curl_exec ($ ch); curl_close ($ ch); // close curl resources, and release system Resources $ result = json_decode ($ content, true); if (! Empty ($ result) {return $ result;} else {return $ content ;}}

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.