PHP code example of fsilva / http-message

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

    

fsilva / http-message example snippets

bash
# Install Composer
curl -sS https://getcomposer.org/installer | php
 php
use Fsilva/HttpMessage/Message;
use Fsilva/HttpMessage/Stream/Buffer;

$message = new Message();
$body = new Buffer();
$body->write(json_encode(['some' => 'value']));

$request = $message->withProtocolVersion(Message::HTTP_1_1)
    ->withHeader('X-Requested-With', 'XMLHttpRequest')
    ->withHeader('User-Agent', 'PHP Request call')
    ->withBody($body)
    ->withoutHeader('pragma')
    ->withAddedHeader('X-Forwarded-For', ['client1', 'proxy1', 'proxy2']);
    
$strMessage = "GET / HTTP/". $request->getProtocolVersion();

foreach($request->getHeaders() as $name => $values) {
    $strMessage .= "\n{$name}: ". implode(', ', $values);
}

// $strMessage is now a very simple HTTP message.
$strMessage .= "\n\n". $request->getBody()->getContents();