bitmannl / codeigniter-curl
该包最新版本(1.3.1)没有提供许可证信息。
使用 Composer 安装 codeigniter-curl(philsturgeon)
1.3.1
2015-12-22 14:06 UTC
This package is not auto-updated.
Last update: 2024-09-18 08:26:37 UTC
README
!!! 已废弃 !!!
此包不再积极维护。如果有人提交包含重大安全漏洞的拉取请求,我会合并它,但除此之外,我不再使用 CodeIgniter Curl 进行任何事情。框架特定的代码是我2009年构建此包时认为很酷的事情,但从那以后几乎没有触碰过。请使用框架无关的等效代码,如 Guzzle 或 Requests。
CodeIgniter-cURL 是一个 CodeIgniter 库,它简化了简单的 cURL 请求,并使更复杂的 cURL 请求更加容易。
要求
- PHP 5.1+
- CodeIgniter 1.7.x - 2.0-dev
- PHP 5(已配置启用 cURL)
- libcurl
功能
- 通过 HTTP 执行 POST/GET/PUT/DELETE 请求
- HTTP 身份验证
- 遵循重定向
- 返回错误字符串
- 提供调试信息
- 代理支持
- cookies
示例
$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