dev-main 2022-03-28 21:04 UTC

This package is not auto-updated.

Last update: 2024-09-26 02:21:07 UTC


README

与 http 相关的工具。

教程

使用 composer 安装

composer require thirdplace/http:dev-main

手动安装

wget https://git.sr.ht/~thirdplace/http/blob/main/http.php

示例用法

<?php

try {
    $result = Thirdplace\get('https://example.com', ['timeout' => 3]);
} catch (\RuntimeException $e) {
    exit("hmm\n");
}

if ($result['code'] === 200) {
    print $result['body'];
} else {
    print "oh\n";
}

说明

返回一个包含 codebody 的关联数组。使用 curl。如果 curl 失败,则抛出 \RuntimeException

如何做

参考

function get(string $url, array $config = []): array