unikent/curl

Laravel Curl 助手库。

5.0.8 2015-06-18 08:59 UTC

This package is not auto-updated.

Last update: 2024-09-14 16:08:24 UTC


README

Laravel-cURL 是由 Phil 的 Codeigniter-cURL([http://philsturgeon.co.uk/code/codeigniter-curl])发展而来的库,使得进行简单的 cURL 请求变得更加容易,同时也使得更复杂的 cURL 请求更加简单。

要求

  1. PHP 5.1+
  2. Laravel 3
  3. PHP 5(已启用 cURL)
  4. libcurl

特性

  • 通过 HTTP 进行 POST/GET/PUT/DELETE 请求
  • HTTP 认证
  • 遵循重定向
  • 返回错误字符串
  • 提供调试信息
  • 代理支持
  • Cookies

下载

https://github.com/mogetutu/laravel-curl

示例

$this->curl = New 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