在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:PatrickLouys/http开源软件地址:https://github.com/PatrickLouys/http开源编程语言:PHP 100.0%开源软件介绍:Http ComponentInstallationYou can use composer to install this component. The package is:
Basic UsageRequestThe Request class provides an object oriented wrapper around the PHP superglobals. This makes it possible to inject it as a dependency into any of your classes that require it. use Http\HttpRequest;
$request = new HttpRequest($_GET, $_POST, $_COOKIE, $_FILES, $_SERVER, file_get_contents('php://input')); Now you can use the following methods on the $request->getParameter($key, $defaultValue = null);
$request->getFile($key, $defaultValue = null);
$request->getCookie($key, $defaultValue = null);
$request->getParameters();
$request->getQueryParameters();
$request->getBodyParameters();
$request->getRawBody();
$request->getCookies();
$request->getFiles();
$request->getMethod();
$request->getHttpAccept();
$request->getReferer();
$request->getUserAgent();
$request->getIpAddress();
$request->isSecure();
$request->getQueryString(); Please note that both GET and POST parameters are merged together and accessible with ResponseThe use Http\HttpResponse;
$response = new HttpResponse; The response can be modified with following methods: $response->setStatusCode($statusCode, $statusText = null);
$response->addHeader($name, $value);
$response->setHeader($name, $value);
$response->addCookie(Cookie $cookie);
$response->deleteCookie(Cookie $cookie);
$response->setContent($content);
$response->redirect($url); If you don't supply a status text with
The
The following two methods are available to send the response to the client: $response->getHeaders();
$response->getContent(); They can be used like this: foreach ($response->getHeaders() as $header) {
header($header, false);
}
echo $response->getContent(); The second parameter of CookiesTo avoid $cookieBuilder->setDefaultDomain($domain); // defaults to NULL
$cookieBuilder->setDefaultPath($path); // defaults to '/'
$cookieBuilder->setDefaultSecure($secure); // defaults to TRUE
$cookieBuilder->setDefaultHttpOnly($httpOnly); // defaults to TRUE
$cookieBuilder->build($name, $value); // returns the cookie object You can use the following methods to manipulate an existing cookie: $cookie->setValue($value);
$cookie->setMaxAge($seconds);
$cookie->setDomain($domain);
$cookie->setPath($path);
$cookie->setSecure($secure);
$cookie->setHttpOnly($httpOnly); The cookie object can the be used with the Example<?php
use Http\HttpRequest;
use Http\HttpResponse;
use Http\CookieBuilder;
$loader = require_once __DIR__ . '/vendor/autoload.php';
$cookieBuilder = new CookieBuilder;
// Disable the secure flag because this is only an example
$cookieBuilder->setDefaultSecure(false);
$request = new HttpRequest($_GET, $_POST, $_COOKIE, $_FILES, $_SERVER, file_get_contents('php://input'));
$response = new HttpResponse;
$content = '<h1>Hello World</h1>';
$content .= $request->getCookie('TestCookie', 'Cookie is not set.');
if ($request->getParameter('setCookie') === 'true') {
$cookie = $cookieBuilder->build('TestCookie', 'Cookie is set.');
$response->addCookie($cookie);
}
$response->setContent($content);
foreach ($response->getHeaders() as $header) {
header($header);
}
echo $response->getContent(); |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论