用户名 / curl
Laravel Curl 辅助库
dev-master
2014-01-22 19:04 UTC
Requires
- php: >=5.1
- lib-curl: *
This package is auto-updated.
Last update: 2024-09-29 04:25:31 UTC
README
Laravel-cURL
Laravel-cURL 是由 Phil 开发的 Codeigniter-cURL 库的衍生库,它简化了简单的 cURL 请求,并使得更复杂的 cURL 请求也变得容易。
要求
- PHP 5.1+
- Laravel 3
- PHP 5 (已配置启用 cURL)
- libcurl
功能
- 通过 HTTP 进行 POST/GET/PUT/DELETE 请求
- HTTP 认证
- 跟随重定向
- 返回错误字符串
- 提供调试信息
- 代理支持
- Cookie
下载
https://github.com/mogetutu/laravel-curl
示例
$curl = New Curl;
简单调用
这些可以在一行代码中完成所有操作,使生活变得简单。它们返回页面内容,或者在失败时返回 FALSE。
// Simple call to remote URL
echo $curl->simple_get('http://example.com/');
// Simple call to CI URI
$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
$curl->simple_get('http://example.com', array(CURLOPT_PORT => 8080));
$curl->simple_post('http://example.com', array('foo'=>'bar'), array(CURLOPT_BUFFERSIZE => 10));
高级调用
这些方法允许你构建更复杂的请求。
// Start session (also wipes existing/previous sessions)
$curl->create('http://example.com/');
// Option & Options
$curl->option(CURLOPT_BUFFERSIZE, 10);
$curl->options(array(CURLOPT_BUFFERSIZE => 10));
// More human looking options
$curl->option('buffersize', 10);
// Login to HTTP user authentication
$curl->httpLogin('username', 'password');
// Post - If you do not use post, it will just run a GET request
$post = array('foo'=>'bar');
$curl->post($post);
// Cookies - If you do not use post, it will just run a GET request
$vars = array('foo'=>'bar');
$curl->setCookies($vars);
// Proxy - Request the page through a proxy server
// Port is optional, defaults to 80
$curl->proxy('http://example.com', 1080);
$curl->proxy('http://example.com');
// Proxy login
$curl->proxyLogin('username', 'password');
// Execute - returns response
echo $curl->execute();
// Debug data ------------------------------------------------
// Errors
$curl->error_code; // int
$curl->error_string;
// Information
$curl->info; // array