Curl sends get and post requests, curlgetpost
1 function getAction ($ url = '') 2 {3 // a curl request consists of four steps: Initialize, set properties, execute and obtain results, release handle 4 // 1. initialize 5 $ curl = curl_init (); 6 7 // 2. Set attribute 8 curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, false ); // for websites that Skip certificate verification (https), the following error occurs: 9 curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, false); // skip certificate verification 10 11 curl_setopt ($ curl, CURLOPT_URL, $ url); // set the curl request address 12 curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, true); // The returned data does not print 13 14 // 3. Send the request, and receive data 15 $ data = curl_exec ($ curl); 16 17 // 4. release handle 18 curl_close ($ curl); 19 return $ data; // No data json_decode () 20} 21 22 // post request 23 function postAction ($ url = '', $ data = array ()) 24 {25 $ curl = curl_init (); 26 curl_setopt ($ curl, expires, false); 27 curl_setopt ($ curl, CURLOPT_SSL_VERIFYHOST, false); 28 curl_setopt ($ curl, CURLOPT_URL, $ url); 29 curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, true); 30 curl_setopt ($ curl, CURLOPT_POST, true); 31 curl_setopt ($ curl, CURLOPT_POSTFIELDS, $ data ); 32 $ result = curl_exec ($ curl); 33 curl_close ($ curl); 34 return $ result; 35}