PHP POST Request HTTPS interface

Source: Internet
Author: User

/** * POST request HTTPS interface return content * @param string $url [requested URL address] * @param string $post [requested parameter] * @return string  */Public Function post_curls ($url, $post) {$curl = Curl_init ();//Start a Curl session curl_setopt ($curl, Curlopt_url, $url); Address to access curl_setopt ($curl, Curlopt_ssl_verifypeer, 0); Inspection of the source of the certification Certificate curl_setopt ($curl, Curlopt_ssl_verifyhost, 1); Check the SSL encryption algorithm for the presence of curl_setopt ($curl, curlopt_useragent, $_server[' http_user_agent ') from the certificate; Simulates user-used browser curl_setopt ($curl, curlopt_followlocation, 1); Use automatic jump curl_setopt ($curl, Curlopt_autoreferer, 1); Auto set Referer curl_setopt ($curl, Curlopt_post, 1); Send a regular POST request curl_setopt ($curl, Curlopt_postfields, $post); Post-Submitted packet curl_setopt ($curl, Curlopt_timeout, 30); Set timeout limit to prevent dead loops curl_setopt ($curl, Curlopt_header, 0); Displays the contents of the Returned header area curl_setopt ($curl, Curlopt_returntransfer, 1); The information obtained is returned as a file stream $res = curl_exec ($curl); // Perform the action if (Curl_errno ($curl)) {echo ' errno '. Curl_error ($curl);//Catch Exception} curl_close ($curl); Turn off the curl session return $res; Return data, JSON format}

Example:

$data [' Param1 ']= ' Red drinkers: '; $data [' Param2 ']= ' There's activity tomorrow! ~ '; $url = ' https://api.xxxxx.com/push/pushAll '; $huawei _res= $this->post_curls ($url, $data);//Return json$huawei_res= Json_decode ($huawei _res,true);

  

/**
* POSTRequestHTTPSInterface Return content
* @paramstring $url [of the requestURLAddress]
* @paramstring $post [Requested Parameters]
* @returnstring
*/
Public functionPost_curls ($url, $post)
{
$curl= Curl_init(); // Start aCURLSession
curl_setopt($curl, Curlopt_url, $url); // the address to be accessed
curl_setopt($curl, Curlopt_ssl_verifypeer, 0); // examination of the source of the certification certificate
curl_setopt($curl, Curlopt_ssl_verifyhost, 1); // Check from certificateSSLWhether the encryption algorithm exists
curl_setopt($curl, curlopt_useragent, $_server[' Http_user_agent ']); // simulating the browser used by the user
curl_setopt($curl, curlopt_followlocation, 1); // Use Auto Jump
curl_setopt($curl, Curlopt_autoreferer, 1); // automatically setReferer
curl_setopt($curl, Curlopt_post, 1); // send a regularPostRequest
curl_setopt($curl, Curlopt_postfields, $post); //PostSubmitted Packets
curl_setopt($curl, Curlopt_timeout, -); // setting a timeout limit to prevent a dead loop
curl_setopt($curl, Curlopt_header, 0); // Displays the returnedHeaderArea content
curl_setopt($curl, Curlopt_returntransfer, 1); // Gets the information returned as a file stream
$res= curl_exec($curl); // Perform actions
off(Curl_errno($curl)) {
Echo' Errno '.Curl_error($curl);//Catch-catching anomaly
}
Curl_close($curl); // CloseCURLsession
return$res; // return data,JSONformat

}

PHP POST Request HTTPS interface

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.