Curl sends get and post requests, curlgetpost

Source: Internet
Author: User

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}

 

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.