Many students feel the first two big (including me) when using curl look at the curl_setopt function of this strip is completely confused, but after you spent 10 minutes looking at my introduction, I believe you can easily fool around with PHP Curl first, Please look at a Curl code (take 10 seconds, look over and then jump to the back) 1 <?php 2 $data = "<soap:envelope>[...] </soap:Envelope> "; 3 $tuCurl = Curl_init (); 4 curl_setopt ($tuCurl, Curlopt_url," https:/ /example.com/path/for/soap/url/"); 5 curl_setopt ($tuCurl, Curlopt_port, 443); 6 curl_setopt ( $tuCurl, Curlopt_verbose, 0); 7 curl_setopt ($tuCurl, Curlopt_header, 0); 8 curl_setopt ($tuCurl , Curlopt_sslversion, 3); 9 curl_setopt ($tuCurl, Curlopt_sslcert, GETCWD (). "/client.pem"); curl_setopt ($tuCurl, Curlopt_sslkey, GETCWD (). "/keyout.pem"); curl_setopt ($tuCurl, Curlopt_cainfo, GETCWD (). "/ca.pem"); curl_setopt ($tuCurl, Curlopt_post, 1); curl_setopt ($tuCurl, Curlopt_ssl_verifypeer, 1); & nbsp curl_setopt ($tuCurl, Curlopt_returntransfer, 1); Curl_setOpt ($tuCurl, Curlopt_postfields, $data); curl_setopt ($tuCurl, Curlopt_httpheader, Array ("content-type:text/ XML "," SOAPAction: \ "/soap/action/query\" "," Content-length: ". strlen ($data)); 17 $tuData = curl_exec ($ Tucurl); if (!curl_errno ($tuCurl)) { $info = Curl_getinfo ($tuCurl); echo ' Took '. $info [' Total_time ']. ' Seconds to send a request to '. $info [' url ']; } else { echo ' Curl error: '. Curl_error ($tuCurl); } -CU Rl_close ($tuCurl); echo $tuData?> WTF, what the hell is going on? Want to learn the use of this "high-end"? First of all, I'm sure you know that most URLs start with HTTP, because they need to be transmitted via HTTP (Hypertext Transfer Protocol Http-hypertext Transfer Protocol), but the transmission of data is not simply the phrase " Hello "to the server to get things done, in order to facilitate the recipient's understanding of the sender's actual intentions and to know who the sender really is, the sender often sends a lot of additional information to the recipient, just as the sender needs an envelope in the letter coat, and the message is written on the envelope with various senders. All of these eventually merged into a thing called message, which forms the basis of the entire Internet. Curl's job is to send these messages via the HTTP protocol (PHP Libcurl currently supports HTTPS, FTP, Telnet, and other protocols) nowLooking at the code, in fact, the code only did five things curl_init () Initialize Curl curl_setopt () to set the transfer data and Parameters Curl_exec () to perform the transfer and get the return Data Curl_errono () return the error code CURL_ Close () Closes curl the following gives data on how to crawl and submit any page using Get and Post methods 1 <?php 2 //initialization 3 $CU RL = Curl_init (); 4 //Set URL 5 curl_setopt ($curl, Curlopt_url, ' http://www.baidu.com '); 6 /Set returns the obtained output for text stream 7 curl_setopt ($curl, Curlopt_returntransfer, true); 8 //execute command 9 $data = curl_exec ($curl); //close URL request curl_close ($curl); //display obtained data Print_r ($data); ?> 15 <?php //init $curl = Curl_init (); /Set URL curl_setopt ($curl, Curlopt_url, ' http://www.baidu.com '); /Set returns the obtained output for text stream curl_setopt ($curl, Curlopt_returntransfer, true); //Set Post method submitted by &nbsP curl_setopt ($curl, Curlopt_post, 1); /Set post data in curl_setopt ($curl, Curlopt_postfields, Array ("Data" => "value"); & nbsp Execute command $data = curl_exec ($curl); /Close URL request curl_close ($curl); //Print data Print_r ($data); ?>
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.