ml/fgc-client

符合HTTPlug规范的file_get_contents HTTP客户端

1.0.1 2016-01-03 18:17 UTC

This package is auto-updated.

Last update: 2024-08-25 20:57:26 UTC


README

Build Status Code Coverage

这是一个基于file_get_contents的HTTPlug规范HTTP客户端。

安装

使用fgc-client最简单的方式是将它作为依赖项集成到项目的composer.json文件中

php composer.phar require ml/fgc-client ^1.0

请注意,HTTPlug尚未发布稳定版本。因此,目前您需要在composer.json文件中将最小稳定性设置为beta

{
    ...
    "minimum-stability": "beta",
    "require": {
        ...
}

使用方法

在安装所需的依赖项后

php composer.phar require guzzlehttp/psr7 ^1.0 php-http/message ^0.2

发起HTTP请求非常简单

require_once('vendor/autoload.php');

use Http\Message\MessageFactory\GuzzleMessageFactory;
use Http\Message\StreamFactory\GuzzleStreamFactory;
use ML\FgcClient\FgcHttpClient;

$messageFactory = new GuzzleMessageFactory();
$client = new FgcHttpClient($messageFactory, new GuzzleStreamFactory());

$request = $messageFactory->createRequest('GET', 'http://example.com/');
$response = $client->sendRequest($request);

echo $response->getStatusCode();