Curl's post submission XML

Source: Internet
Author: User

Directly on the code:

1     /** 2 * Submit XML to the corresponding interface URL by post3      * 4 * @param string $xml XML data that requires post5 * @param string $url URL6 * @param bool $useCert Whether a certificate is required and is not required by default7 * @param int $second URL Execution time-out, default 30s8 * @throws wxpayexception9      */Ten     Private Static functionPostxmlcurl ($xml,$url,$useCert=false,$second= 30)  One     {     A         $ch=curl_init (); -         //Set Timeout -curl_setopt ($ch, Curlopt_timeout,$second); the      -         //If you have a configuration agent, set up proxy here -         if(Wxpayconfig::curl_proxy_host! = "0.0.0.0" -&& Wxpayconfig::curl_proxy_port! = 0){  +curl_setopt ($ch, Curlopt_proxy, Wxpayconfig::curl_proxy_host); -curl_setopt ($ch, Curlopt_proxyport, Wxpayconfig::curl_proxy_port); +         }    Acurl_setopt ($ch, Curlopt_url,$url); atcurl_setopt ($ch, Curlopt_ssl_verifypeer,TRUE); -curl_setopt ($ch, curlopt_ssl_verifyhost,2);//Strict Calibration - //Set Header -curl_setopt ($ch, Curlopt_header,FALSE); -         //request result As string and output to screen -curl_setopt ($ch, Curlopt_returntransfer,TRUE); in      -         if($useCert==true){ to             //Setting up Certificates + //Use Certificate: Cert and key belong to two. Pem files respectively -curl_setopt ($ch, Curlopt_sslcerttype, ' PEM '); thecurl_setopt ($ch, Curlopt_sslcert, Wxpayconfig::Sslcert_path); *curl_setopt ($ch, Curlopt_sslkeytype, ' PEM '); $curl_setopt ($ch, Curlopt_sslkey, Wxpayconfig::Sslkey_path);Panax Notoginseng         } -         //Post Submission Method thecurl_setopt ($ch, Curlopt_post,TRUE); +curl_setopt ($ch, Curlopt_postfields,$xml); A         //Run Curl the         $data= Curl_exec ($ch); +         //return Results -         if($data){ $Curl_close ($ch); $             return $data; -}Else { -             $error= Curl_errno ($ch); theCurl_close ($ch); -             Throw NewWxpayexception ("Curl Error, error code:$error");Wuyi         } the}

response.php

1 <? PHP 2 if (isset($_post[' name ')]) {3     if (! Empty ($_post[' name '])) {4         echo ' Hello, ',$_post[' name ']. '! '; 5     }6}7 ?>       

Curl's post submission XML

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.