umonkey / php-http-client

简单的HTTP客户端

1.2.0 2020-07-01 10:00 UTC

This package is auto-updated.

Last update: 2024-08-29 05:36:59 UTC


README

适用于基于Slim框架的个人项目的非常基础的HTTP客户端。

用法

$settings = [
    'httpClient' => [
        'cache_size_limit' => 1048576,  // 1 MB
        'cache_ttl' => 86400,  // 1 day
    ],
];

$http = new \Umonkey\Http($logger, $settings);

$res = $http->fetch($url);

if ($res->getStatus() !== 200) {
    throw new \RuntimeException('error fetching resource');
}

var_dump($res);

在Slim项目中,将以下内容添加到 config/dependencies.php

$container['http'] = function ($c) {
    return $c['callableResolver']->getClassInstance('Umonkey\HttpClient');
};

变更

2020/07/01:

  • 添加了 HttpClient::urljoin() 方法。
  • 添加了URL重写。