bee4/httpclient

此包已被弃用且不再维护。作者建议使用bee4/transport包代替。

一个简单的链式传输客户端。

v2.0.0 2016-08-31 16:37 UTC

README

Build Status Scrutinizer Code Quality Code Coverage SensiolabInsight

License

这个库是一个传输客户端,可用于处理HTTP、FTP、FTPS、SFTP、SCP调用。所有协议以相同的方式处理,API是一个简单的请求 > 响应机制。

它受到Guzzle 3实现的启发,采用更简单的方法(没有curl_multi,没有SSL...),只处理请求和响应。目前cURL是唯一的实现,所有请求选项都是CURL_*选项...

安装

Latest Stable Version Total Downloads

可以使用Composer安装此项目。将以下内容添加到您的composer.json中

{
    "require": {
        "bee4/transport": "~1.2"
    }
}

或运行此命令

composer require bee4/transport:~1.2

示例

您必须创建一个Client实例,然后构建请求并发送以获取响应。

<?php
$client = new Bee4\Transport\MagicHandler();
$request = $client->get('http://www.example.com', ['Accept: text/html']);
$response = $request->send();

$respose->getStatusMessage(); //Retrieve the status definition example: 301 Moved Permanently
$respose->getBody(); //Retrieve response content

//The same is possible with FTP
$request = $client->head('ftp://user@pass:host.com/path')->send();
//Remove a file
$client->delete('ftp://user@pass:host.com/path/to/file.php')->send();

//And SFTP - Upload a file
$client->put('sftp://user@pass:host.com/path/to/file.php')
  ->setBody('File content here')
  ->send();

在HTTP方法名称和客户端调用之间进行映射,以保持相同的API

  • head用于检查资源是否存在;
  • get用于检索资源;
  • put用于上传资源;
  • delete用于删除资源。

其他方法仅通过HTTP:POST处理。