lucky-loek/really-simple-http-requests

此包已被弃用且不再维护。未建议替代包。

为想要轻松发送请求并期望返回状态码和正文的人提供的包。

1.1.0 2019-07-29 07:55 UTC

This package is auto-updated.

Last update: 2021-05-09 14:38:41 UTC


README

Build Status

一个用于PHP中实现简单HTTP请求的不依赖于框架的包装器。

这是一个为想要轻松发送请求并期望返回状态码和正文的人准备的包。没有更多,也没有更少。

安装

$ composer require lucky-loek/really-simple-http-requests

或者添加到您的 composer.json 文件中

"require": {
    "lucky-loek/really-simple-http-requests": "^1.0"
}

使用方法

$request = new Request(
    'www.httpbin.org/post',
    'post',
    'This is a nice body!',
    [
        'X-Csrf-Token' => 'notSoSafeToken'
    ]
);

$response = $request->send();

echo $response->getBody();
echo $response->getStatusCode();

// You can secretly take a look at the headers too!
echo $response->getHeader('Content-Length');

// Get them all!
foreach $response->getAllHeaders() as $header {
    echo $header;
}