该软件包已被废弃且不再维护。作者建议使用 php-http/httplug 软件包。

PHP7面向对象的cURL扩展包装器

1.1.3 2016-08-20 23:53 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:56:27 UTC


README

这是一个PHP7面向对象的cURL扩展包装器。

安装

composer require flexyproject/curl

使用方法

require 'vendor/autoload.php';

use \FlexyProject\Curl\Client;

// Create Client object
$curl = new Client();

// Set Url
$curl->setUrl('https://api.github.com/user');

// Set options (here authentication options)
$curl->setOption([
	CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
	CURLOPT_USERPWD  => sprintf('%s:%s', 'user', 'pass')
]);

// Success callback
$curl->success(function (Client $instance) {
	$instance->getHeaders(); // Get headers info
	$instance->getResponse(); // Get response body
});
// Error callback
$curl->error(function (Client $instance) {
	$instance->getHeaders(); // Get headers info
	$instance->getResponse(); // Get response body
});

// Perform request
$curl->perform();