Ways to implement get and post requests using curl in PHP

Source: Internet
Author: User

Curl is a PHP tool class and is used as a reference to the official documentation: http://php.net/manual/zh/book.curl.php

There are detailed instructions for use and parameter introduction.

    /** * @param string $url * @return Mixed*/     Public functionDoget ($url)    {        //Initialize        $ch=Curl_init (); curl_setopt ($ch, Curlopt_url,$url); //Do not print directly after executioncurl_setopt ($ch, Curlopt_returntransfer,true); curl_setopt ($ch, Curlopt_header,false); //Skip Certificate Checkcurl_setopt ($ch, Curlopt_ssl_verifypeer,false); //do not check for the existence of SSL encryption algorithms from the certificatecurl_setopt ($ch, Curlopt_ssl_verifyhost,false); //execute and get HTML document content        $output= Curl_exec ($ch); //releasing the curl handleCurl_close ($ch); return $output; }    /** * @param string $url * @param array $post _data * @param array | Boolean $header * @return Mixed */     Public functionDoPost ($url,$post _data,$header)    {        $ch=Curl_init (); curl_setopt ($ch, Curlopt_url,$url); //Do not print directly after executioncurl_setopt ($ch, Curlopt_returntransfer,true); //set the request mode to postcurl_setopt ($ch, Curlopt_post,true); //Variables for postcurl_setopt ($ch, Curlopt_postfields,$post _data); //request headers, which can be passed to an arraycurl_setopt ($ch, Curlopt_header,$header); //Skip Certificate Checkcurl_setopt ($ch, Curlopt_ssl_verifypeer,false); //do not check for the existence of SSL encryption algorithms from the certificatecurl_setopt ($ch, Curlopt_ssl_verifyhost,false); $output= Curl_exec ($ch); Curl_close ($ch); return $output; }

Where the certificate is skipped in order to access HTTPS.

How to implement get and post requests using curl in PHP

Related Article

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.