Php-implemented Curl encapsulation class Curl. class. php Usage instance analysis

Source: Internet
Author: User
This article mainly introduces the Curl encapsulation class Curl implemented by php. class. php Usage, detailed analysis of the Curl encapsulation Class Definition and related usage skills in the form of a complete instance, has some reference value, you can refer to the example in this article to describe the Curl encapsulation class Curl implemented by php. class. php usage. Share it with you for your reference. The details are as follows:

 $ Val) {$ sets [] = $ key. '= '. urlencode ($ val) ;}$ fields = implode ('&', $ sets);} curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ fields );} else if ('put' ==$ method) {curl_setopt ($ ch, CURLOPT_PUT, true) ;}// curl_setopt ($ ch, CURLOPT_PROGRESS, true ); // curl_setopt ($ ch, CURLOPT_VERBOSE, true); // curl_setopt ($ ch, CURLOPT_MUTE, false); curl_setopt ($ ch, CURLOPT_TIMEOUT, 10 ); // Set curl timeout seconds if (strlen ($ userAgent) {cur Rochelle setopt ($ ch, CURLOPT_USERAGENT, $ userAgent);} if (is_array ($ httpHeaders) {curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ httpHeaders );} $ ret = curl_exec ($ ch); if (curl_errno ($ ch) {curl_close ($ ch); return array (curl_error ($ ch ), curl_errno ($ ch);} else {curl_close ($ ch); if (! Is_string ($ ret) |! Strlen ($ ret) {return false;} return $ ret;} function post ($ url, $ fields, $ userAgent = '', $ httpHeaders = '', $ username = '', $ password ='') {$ ret = Curl: execute ('post', $ url, $ fields, $ userAgent, $ httpHeaders, $ username, $ password); if (false ===$ ret) {return false;} if (is_array ($ ret) {return false;} return $ ret ;} function get ($ url, $ userAgent = '', $ httpHeaders ='', $ username = '', $ pas Sword = '') {$ ret = Curl: execute ('GET', $ url,'', $ userAgent, $ httpHeaders, $ username, $ password ); if (false ===$ ret) {return false;} if (is_array ($ ret) {return false;} return $ ret;} function create () {$ ch = null; if (! Function_exists ('curl _ init ') {return false;} $ ch = curl_init (); if (! Is_resource ($ ch) {return false;} return $ ch ;}}?>

GET usage:

$curl = new Curl();$curl->get('http://www.XXX.com/');

POST usage:

$curl = new Curl();$curl->get('http://www.XXX.com/', 'p=1&time=0');

I hope this article will help you with php programming.

For more articles on Curl encapsulation class Curl. class. php Usage instance analysis implemented by php, refer to PHP Chinese website!

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.