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 ;}}