rogeriopradoj/codeigniter-curl

该软件包最新版本(1.2.2)没有提供许可证信息。

通过composer使用philsturgeon的codeigniter-curl库

安装次数: 2,070

依赖项: 1

建议者: 0

安全性: 0

星标: 0

关注者: 3

分支: 323

类型:codeigniter-spark

1.2.2 2013-05-27 21:19 UTC

This package is not auto-updated.

Last update: 2024-09-23 14:18:22 UTC


README

CodeIgniter-cURL是一个CodeIgniter库,它使简单的cURL请求变得简单,同时也使更复杂的cURL请求变得更容易。

要求

  1. PHP 5.1+
  2. CodeIgniter 1.7.x - 2.0-dev
  3. PHP 5(已配置启用cURL)
  4. libcurl

特性

  • 通过HTTP进行POST/GET/PUT/DELETE请求
  • HTTP身份验证
  • 跟随重定向
  • 返回错误字符串
  • 提供调试信息
  • 代理支持
  • Cookie

下载

http://philsturgeon.co.uk/code/codeigniter-curl

示例

$this->load->library('curl'); 

简单调用

这些调用一行代码即可完成,使生活更简单。它们返回网页内容,或在失败时返回FALSE。

// Simple call to remote URL
echo $this->curl->simple_get('http://example.com/');

// Simple call to CI URI
$this->curl->simple_post('controller/method', array('foo'=>'bar'));

// Set advanced options in simple calls
// Can use any of these flags http://uk3.php.net/manual/en/function.curl-setopt.php

$this->curl->simple_get('http://example.com', array(CURLOPT_PORT => 8080));
$this->curl->simple_post('http://example.com', array('foo'=>'bar'), array(CURLOPT_BUFFERSIZE => 10)); 

高级调用

这些方法允许您构建更复杂的请求。

// Start session (also wipes existing/previous sessions)
$this->curl->create('http://example.com/');

// Option & Options
$this->curl->option(CURLOPT_BUFFERSIZE, 10);
$this->curl->options(array(CURLOPT_BUFFERSIZE => 10));

// More human looking options
$this->curl->option('buffersize', 10);

// Login to HTTP user authentication
$this->curl->http_login('username', 'password');

// Post - If you do not use post, it will just run a GET request
$post = array('foo'=>'bar');
$this->curl->post($post);

// Cookies - If you do not use post, it will just run a GET request
$vars = array('foo'=>'bar');
$this->curl->set_cookies($vars);

// Proxy - Request the page through a proxy server
// Port is optional, defaults to 80
$this->curl->proxy('http://example.com', 1080);
$this->curl->proxy('http://example.com');

// Proxy login
$this->curl->proxy_login('username', 'password');

// Execute - returns responce
echo $this->curl->execute();

// Debug data ------------------------------------------------

// Errors
$this->curl->error_code; // int
$this->curl->error_string;

// Information
$this->curl->info; // array