1. Go to this page and download the library: Download httpsoft/http-response library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
httpsoft / http-response example snippets
use HttpSoft\Message\Response;
$response = new Response();
// default values
$response->getStatusCode(); // 200
$response->getReasonPhrase(); // 'OK'
$response->getBody()->getContents(); // ''
$response->getBody()->getMetadata('uri') // 'php://temp'
$response->getHeaders(); // []
$response->getProtocolVersion(); // '1.1'
// Create with the passed parameters
$response = new Response(404, ['Content-Language' => 'en'], 'php://memory', '2');
$response->getStatusCode(); // 404
$response->getReasonPhrase(); // 'Not Found'
$response->getBody()->getContents(); // ''
$response->getBody()->getMetadata('uri') // 'php://memory'
$response->getHeaders(); // ['Content-Language' => ['en']]
$response->getProtocolVersion(); // '2'
// Write to the response body:
$response->getBody()->write('Content');
$response->getBody()->getContents(); // 'Content'
// With `Content-Type` header:
$newResponse = $response->withHeader('Content-Type', 'text/plain');
$newResponse->getHeaderLine('content-type'); // 'text/plain'
$newResponse->getHeaders(); // ['Content-Language' => ['ru'], 'Content-Type' => ['text/plain']]
// With status code:
$newResponse = $response->withStatus(500);
$newResponse->getStatusCode(); // 500
$newResponse->getReasonPhrase(); // 'Internal Server Error'
// With status code and reason phrase:
$newResponse = $response->withStatus(599, 'Custom Phrase');
$newResponse->getStatusCode(); // 599
$newResponse->getReasonPhrase(); // 'Custom Phrase'
// Create `Psr\Http\Message\ResponseInterface` instance from HTML:
$response = new HttpSoft\Response\HtmlResponse('<p>HTML</p>');
$response->getHeaderLine('content-type'); // 'text/html; charset=UTF-8'
// Create `Psr\Http\Message\ResponseInterface` instance from data to convert to JSON:
$response = new HttpSoft\Response\JsonResponse(['key' => 'value']);
$response->getHeaderLine('content-type'); // 'application/json; charset=UTF-8'
// Create `Psr\Http\Message\ResponseInterface` instance from Text:
$response = new HttpSoft\Response\TextResponse('Text');
$response->getHeaderLine('content-type'); // 'text/plain; charset=UTF-8'
// Create `Psr\Http\Message\ResponseInterface` instance from XML:
$response = new HttpSoft\Response\XmlResponse('<xmltag>XML</xmltag>');
$response->getHeaderLine('content-type'); // 'application/xml; charset=UTF-8'
// Create `Psr\Http\Message\ResponseInterface` instance for redirect:
$response = new HttpSoft\Response\RedirectResponse('https/example.com');
$response->getHeaderLine('location'); // 'https/example.com'
// Create `Psr\Http\Message\ResponseInterface` instance for empty response:
$response = new HttpSoft\Response\EmptyResponse();
$response->getStatusCode(); // 204
$response->getReasonPhrase(); // 'No Content'
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.