PHP function Curl Requests the HTTPS protocol interface API in the form of Get and post respectively

Source: Internet
Author: User

1. Curl requests the HTTPS protocol interface in Get mode

1 functionCurl_get_https ($url){2     $curl= Curl_init ();//start a Curl session3curl_setopt ($curl, Curlopt_url,$url);4curl_setopt ($curl, Curlopt_header, 0);5curl_setopt ($curl, Curlopt_returntransfer, 1);6curl_setopt ($curl, Curlopt_ssl_verifypeer,false);//Skip Certificate Check7curl_setopt ($curl, Curlopt_ssl_verifyhost,true);//Check that the SSL encryption algorithm exists from the certificate8     $tmpInfo= Curl_exec ($curl);//returns the JSON object for the API9 //Close URL requestTenCurl_close ($curl); One     return $tmpInfo;//returns a JSON object A}

2. Curl requests the HTTPS protocol interface in post mode

1 functionCurl_post_https ($url,$data){//Analog commit data function2     $curl= Curl_init ();//start a Curl session3curl_setopt ($curl, Curlopt_url,$url);//the address to be accessed4curl_setopt ($curl, Curlopt_ssl_verifypeer, 0);//examination of the source of the certification certificate5curl_setopt ($curl, Curlopt_ssl_verifyhost, 1);//Check that the SSL encryption algorithm exists from the certificate6curl_setopt ($curl, Curlopt_useragent,$_server[' http_user_agent ']);//simulating the browser used by the user7curl_setopt ($curl, curlopt_followlocation, 1);//Use Auto Jump8curl_setopt ($curl, Curlopt_autoreferer, 1);//set Referer automatically9curl_setopt ($curl, Curlopt_post, 1);//send a regular POST requestTencurl_setopt ($curl, Curlopt_postfields,$data);//Post-submitted packets Onecurl_setopt ($curl, Curlopt_timeout, 30);//setting a timeout limit to prevent a dead loop Acurl_setopt ($curl, Curlopt_header, 0);//Displays the contents of the header area returned -curl_setopt ($curl, Curlopt_returntransfer, 1);//gets the information returned as a file stream -     $tmpInfo= Curl_exec ($curl);//Perform Actions the     if(Curl_errno ($curl)) { -         Echo' Errno '. Curl_error ($curl);//Catch-catching anomaly -     } -Curl_close ($curl);//turn off the curl session +     return $tmpInfo;//return data, JSON format -}

PHP function Curl Requests the HTTPS protocol interface API in the form of Get and post respectively

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.