Php:curl request HTTPS protocol API with Get and post respectively

Source: Internet
Author: User

1. Curl requests the HTTPS protocol interface in Get mode

// Note: The address here has a parameter, without parameters you handle it yourself oh get is simple
functionCurl_get_https ($url){    $curl= Curl_init ();//start a Curl sessioncurl_setopt ($curl, Curlopt_url,$url); curl_setopt ($curl, Curlopt_header, 0); curl_setopt ($curl, Curlopt_returntransfer, 1); curl_setopt ($curl, Curlopt_ssl_verifypeer,false);//Skip Certificate Checkcurl_setopt ($curl, Curlopt_ssl_verifyhost,true);//Check that the SSL encryption algorithm exists from the certificate    $tmpInfo= Curl_exec ($curl);//returns the JSON object for the API//close URL requestCurl_close ($curl); return $tmpInfo;//returns a JSON object}

2. Curl requests the HTTPS protocol interface in post mode

/*PHP CURL HTTPS POST*/functionCurl_post_https ($url,$data){//Analog commit data function    $curl= Curl_init ();//start a Curl sessioncurl_setopt ($curl, Curlopt_url,$url);//the address to be accessedcurl_setopt ($curl, Curlopt_ssl_verifypeer, 0);//examination of the source of the certification certificatecurl_setopt ($curl, Curlopt_ssl_verifyhost, 1);//Check that the SSL encryption algorithm exists from the certificatecurl_setopt ($curl, Curlopt_useragent,$_server[' http_user_agent ']);//simulating the browser used by the usercurl_setopt ($curl, curlopt_followlocation, 1);//Use Auto Jumpcurl_setopt ($curl, Curlopt_autoreferer, 1);//set Referer automaticallycurl_setopt ($curl, Curlopt_post, 1);//send a regular POST requestcurl_setopt ($curl, Curlopt_postfields,$data);//Post-submitted packetscurl_setopt ($curl, Curlopt_timeout, 30);//setting a timeout limit to prevent a dead loopcurl_setopt ($curl, Curlopt_header, 0);//Displays the contents of the header area returnedcurl_setopt ($curl, Curlopt_returntransfer, 1);//gets the information returned as a file stream    $tmpInfo= Curl_exec ($curl);//Perform Actions    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:curl request HTTPS protocol API with 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.