genxoft/curl

支持RESTful的简单php cURL扩展

v1.1-beta 2018-11-14 19:14 UTC

This package is auto-updated.

Last update: 2024-09-18 10:23:36 UTC


README

支持REST方法的简单curl包装器

  • GET
  • HEAD
  • POST
  • PUT
  • PATCH
  • DELETE

需求

  • PHP 5.4+
  • curl php扩展

安装

安装此包装器的首选方式是通过composer

php composer.phar require genxoft/curl "*"

composer require genxoft/curl "*"

快速使用

快速GET请求

require_once __DIR__ . '/vendor/autoload.php';
use genxoft\curl\Curl;

$result = Curl::QuickGet("http://example.com", ["text_param" => "text_value"]);

您还可以查看Curl::QuickPost和Curl::QuickJson快速方法

基本使用

带有Json数据的POST请求

执行带有Json数据和查询参数的POST请求

require_once __DIR__ . '/vendor/autoload.php';
use genxoft\curl\Curl;
use genxoft\curl\Request;

$request = new Request("http://example.com");
$request->addGetParam("action", "save")
    ->setJsonBody([
        "name" => "John Smith",
        "age" => 23
    ]);
$curl = new Curl($request);
$response = $curl->post();

if ($response === null) {
    echo $curl->getLastError();
} else {
    if ($response->isSuccess()) {
        echo "Data saved";
    } else {
        echo "HTTP Error: ".$response->getStatusMessage();
    }
}

捐赠

许可证

此curl包装器在MIT许可证下发布。