Php curl is not so complicated, and phpcurl is also complicated _ PHP Tutorial

Source: Internet
Author: User
Php curl is not so complex, and phpcurl is also complex. Php's curl is not so complicated, and phpcurl is also complicated. many people feel that the first time they use curl, they have two large headers (including me ), looking at these curl_setopt functions, php curl is not that complicated, and phpcurl is also complicated.

When I used curl for the first time, many of my colleagues felt like the first two big ones (including me). They were totally confused by the curl_setopt function, however, after reading my introduction for 10 minutes, I believe you will be able to play with php curl easily in the future.

First, read a curl code (it takes 10 seconds to read it again, and then jump to the next article)

 1 
 [...]";  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"); 10 curl_setopt($tuCurl, CURLOPT_SSLKEY, getcwd() . "/keyout.pem"); 11 curl_setopt($tuCurl, CURLOPT_CAINFO, getcwd() . "/ca.pem"); 12 curl_setopt($tuCurl, CURLOPT_POST, 1); 13 curl_setopt($tuCurl, CURLOPT_SSL_VERIFYPEER, 1); 14 curl_setopt($tuCurl, CURLOPT_RETURNTRANSFER, 1); 15 curl_setopt($tuCurl, CURLOPT_POSTFIELDS, $data); 16 curl_setopt($tuCurl, CURLOPT_HTTPHEADER, array("Content-Type: text/xml","SOAPAction: \"/soap/action/query\"", "Content-length: ".strlen($data))); 17 18 $tuData = curl_exec($tuCurl); 19 if(!curl_errno($tuCurl)){ 20   $info = curl_getinfo($tuCurl); 21   echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url']; 22 } else { 23   echo 'Curl error: ' . curl_error($tuCurl); 24 } 25 26 curl_close($tuCurl); 27 echo $tuData; 28 ?>

WTF, what is this?

Do you want to learn this "high-end" usage?

First of all, I believe you must know that most websites start with http because they need to transmit data through http (Hypertext transfer protocol HTTP-Hypertext transfer protocol, however, it is not easy to transmit a "Hello" sentence to the server. the sender understands the actual intention of the sender and knows who the sender is, the sender often sends a large amount of additional information to the recipient, just as the sender needs to write a variety of sender information on the envelope. All these are combined into a message, which forms the foundation of the entire Internet.

Curl sends these messages over http (php libcurl currently supports https, ftp, telnet, and other protocols)

Now let's look at the code. actually, the code only does five things.

The following describes how to capture and submit any page data using the GET and POST methods.
1
 15 16
 "Value"); 27 // execute command 28 $ data = curl_exec ($ curl); 29 // close URL request 30 curl_close ($ curl ); 31 // print data 32 print_r ($ data); 33?>

For more information about curl usage, see the official php documentation.

When using curl for the first time, many people felt that the first two were big (including me). they looked at these curl_setopt functions completely...

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.