1. Go to this page and download the library: Download maplephp/http 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/ */
maplephp / http example snippets
use MaplePHP\Http;
$request = new Http\ServerRequest(UriInterface $uri, EnvironmentInterface $env);
echo $request->getMethod(); // GET, POST, PUT, DELETE
$uri = $request->getUri(); // UriInterface
echo $uri->getScheme(); // https
echo $uri->getAuthority(); // [userInfo@]host[:port]
echo $uri->getUserInfo(); // username:password
echo $uri->getHost(); // example.com, staging.example.com, 127.0.0.1, localhost
echo $uri->getPort(); // 443
echo $uri->getPath(); // /about-us/workers
echo $uri->getQuery(); // page-id=12&filter=2
echo $uri->getFragment(); // anchor-12 (The anchor hash without "#")
echo $uri->getUri(); // Get the full URI
$stream = new Http\Stream(Http\Stream::TEMP);
$response = new Http\Response($stream);
$env = new Http\Environment();
$request = new Http\ServerRequest(new Http\Uri($env->getUriParts()), $env);
$stream = new Http\Stream(
(mixed) Stream
(string) permission
);
$stream = new Http\Stream(Http\Stream::TEMP);
if ($stream->isSeekable()) {
$stream->write("Hello world");
//echo $stream; // will print Hello world
// Or
$stream->rewind();
echo $stream->getContents(); // Hello world
// Or Same as above
//echo $stream->read($stream->getSize());
}
$stream = new Http\Stream("/var/www/html/YourApp/dir/dir/data.json");
echo $stream->getContents();
$upload = new Http\UploadedFile($stream);
$upload->moveTo("/var/www/html/upload/log.txt"); // Place Hello world in txt file
// Init request client
$client = new Http\Client([CURLOPT_HTTPAUTH => CURLAUTH_DIGEST]); // Pass on Curl options
// Create request data
$request = new Http\Request(
"POST", // The HTTP Method (GET, POST, PUT, DELETE, PATCH)
"https://admin:[email protected]:443/test.php", // The Request URI
["customHeader" => "lorem"], // Add Headers, empty array is allowed
["email" => "[email protected]"] // Post data
);
// Pass request data to client and POST
$response = $client->sendRequest($request);
// Get Stream data
var_dump($response->getBody()->getContents());
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.