PHP code example of gandung / http-message

1. Go to this page and download the library: Download gandung/http-message 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/ */

    

gandung / http-message example snippets

://input
://temp

use Gandung\Psr7\Response;

$content = 'this is a text.';
$response = new Response($content, 200, ['Content-Type' => 'text/plain']);

echo sprintf("%s\n", $response);

use Gandung\Psr7\PhpTempStream;
use Gandung\Psr7\Response;

$content = 'this is a text.';
$stream = new PhpTempStream;
$stream->write($content);
$response = new Response($stream, 200, ['Content-Type' => 'text/plain']);

echo sprintf("%s\n", $response);

use Gandung\Psr7\Response;

$handler = fopen('php://temp', 'r+b');
fseek($handler, 0);
fwrite($handler, 'this is a text.');
$response = new Response($handler, 200, ['Content-Type' => 'text/plain']);

echo sprintf("%s\n", $response);

use Gandung\Psr7\PhpTempStream;

$stream = new PhpTempStream;
$stream->write('this is a text.');

echo sprintf("%s\n", (string)$stream);

use Gandung\Psr7\Stream;

$handler = fopen('your-file', 'r');
fseek($handler, 0);
fwrite($handler, 'this is a text.');
$stream = new Stream($handler);

echo sprintf("%s\n", (string)$stream);