Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

rgamba/httpclient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

4 Commits

Repository files navigation

httpclient

PHP Http Client is a fully featured HTTP client created 100% in PHP. It doesn't use cURL or other external libraries.

Usage

A very basic http request:

get("/info.php"); echo $http->getBody(); // Just print the response body">
require_once('httpclient.php');
$http = new HttpClient("http://mydomain.com");
$http->get("/info.php");
echo $http->getBody(); // Just print the response body

Can also be written like this:

get(); echo $http->getBody(); // Just print the response body">
require_once('httpclient.php');
$http = new HttpClient("http://mydomain.com/info.php");
$http->get();
echo $http->getBody(); // Just print the response body

Headers and response status codes

setHeader("Content-Type","application/x-www-form-urlencoded"); $http->post("/login.php", array( "username" => "rgamba@gmail.com", "password" => "mypasswd123" )); echo "The response status code is: " . $http->status()->number . " with the message: " . $http->status()->msg; echo $http->getBody(); // Just print the response body echo "The Server response header is: " . $http->getHeader("Server");">
require_once('httpclient.php');
$http = new HttpClient("http://mydomain.com");
$http->setHeader("Content-Type","application/x-www-form-urlencoded");
$http->post("/login.php", array(
"username" => "rgamba@gmail.com",
"password" => "mypasswd123"
));
echo "The response status code is: " . $http->status()->number . " with the message: " . $http->status()->msg;
echo $http->getBody(); // Just print the response body
echo "The Server response header is: " . $http->getHeader("Server");

Authorization

basicAuth("username","passwd"); // Or use digest auth... // http->digestAuth("username","passwd"); $http->get("/secure") echo $http->getBody(); // Just print the response body">
require_once('httpclient.php');
$http = new HttpClient("http://mydomain.com");
$http->basicAuth("username","passwd");
// Or use digest auth...
// http->digestAuth("username","passwd");
$http->get("/secure")
echo $http->getBody(); // Just print the response body

Allow redirects and accept cookies

allowRedirects(true, 2); $http->acceptCookies(true) $http->get("/main") echo $http->getBody(); // Just print the response body">
require_once('httpclient.php');
$http = new HttpClient("http://mydomain.com");
$http->allowRedirects(true, 2);
$http->acceptCookies(true)
$http->get("/main")
echo $http->getBody(); // Just print the response body

About

PHP Http Client

Resources

Readme

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors

Languages