iothost/phpresponse

一个简单的PHP类,用于正确处理HTTP响应。

1.0.0 2017-03-20 10:44 UTC

This package is not auto-updated.

Last update: 2024-09-28 20:45:01 UTC


README

##iothost/phpresponse

一个简单的PHP类,用于正确处理响应。

####安装 composer require iothost/phpresponse

####示例用法

$loader = require './vendor/autoload.php';
$response = new \Iothost\PhpResponse\Response();

// add header
$response->addHeader('Cache-Control: no-cache');

// set Content-Type, can be entered as a string
$response->addHeader($response::CT_TEXT);

// set HTTP status code, can be entered as a number (int)
$response->setStatus($response::STATUS_OK);

// set response body as a string
$response->setBody($string);
// OR
// set response body as JSON (from array)
$response->setBodyJson($array);


// send response
$response->send();