mogetutu/curl

该软件包已被废弃且不再维护。作者建议使用guzzle/guzzle软件包代替。

简单的Curl PHP辅助库

dev-master 2015-04-08 12:13 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:28:25 UTC


README

Simple PHP-cURL库

要求

  1. PHP 5.1+
  2. libcurl

功能

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

下载

https://github.com/mogetutu/simplePHP-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