PHP Classes

PHP HTTP Client Request: Process and send HTTP requests to Web servers

Recommend this page to a friend!
  Info   View files Example   View files View files (20)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 160 This week: 2All time: 8,961 This week: 94Up
Version License PHP version Categories
php-http-client 1.0MIT/X Consortium ...7.0Networking, HTTP, PHP 5
Description 

Author

This package can process and send HTTP requests to Web servers.

It can process the current HTTP request, check if the method is GET or POST, and retrieves specific variable values by name.

The package can also send HTTP GET and POST requests to the server of a given URL with support for basic authentication.

Picture of Muhammad Umer Farooq
Name: Muhammad Umer Farooq is available for providing paid consulting. Contact Muhammad Umer Farooq .
Classes: 52 packages by
Country: Pakistan Pakistan
Age: 22
All time rank: 84611 in Pakistan Pakistan
Week rank: 51 Up3 in Pakistan Pakistan Up
Innovation award
Innovation award
Nominee: 6x

Example

<?php

require '../vendor/autoload.php';

$request = new Lablnet\Request();

// Get the value of _GET['var']
$var = $request->getQuery('var');
//it print the get request
var_dump($var);

// Get the value of $_POST['id']
if ($request->isPost()) {
   
$id = $request->getPost('id');
}

//Response
$config = [
   
'code' => 200,
   
'headers' => [
       
'Content-Type' => 'text/html'
   
]
];

$response = new Lablnet\Response($config);
$response->setBody('This is a plain text file.');

$response->send();

//Redirect to other page/site.
//(new Lablnet\Redirect('https://zestframework.xyz/'));
   
//Using the cURL client
//Send request to https://zestframework.xyz login page with post method
 
$request = $request->curl("https://zestframework.xyz/account/login/action","POST");
 
//Set transfer and return header
$request->setReturnHeader(true)->setReturnTransfer(true);
//Set the fields
$request->setFields([
   
'username' => 'your-username',
   
'password' => 'your-password'
]);
//Send the request
$request->send();
// return => 200
$statusCode = $request->getCode();
// Display the body of the returned response
echo "<br\>".$request->getBody();
   


Details

PHP HTTP Client

http-client is the php package. It provides the ability to manage and parse request object. It also provides support for HTTP client transactions via cURL.

Requirement

  • PHP
  • Composer

install

run this command


## BASIC USAGE

### The request object, GET example
Let's use a GET request with the URL '/index.php?var=value'


<?php require '../vendor/autoload.php';

$request = new Lablnet\Request();

// Get the value of _GET['var'] $var = $request->getQuery('var'); //it print the get request var_dump($var);

### The request object, POST example
Let's use a POST request.

// Get the value of $_POST['id'] if ($request->isPost()) {

$id = $request->getPost('id');

}

### Creating a response object

//Response $config = [

'code'    => 200,
'headers' => [
	'Content-Type' => 'text/html'
]

];

$response = new Lablnet\Response($config); $response->setBody('This is a plain text file.');

$response->send();

### Simple response redirect

//Redirect to other page/site. (new Lablnet\Redirect('https://zestframework.xyz/'));


### Using the cURL client

//Using the cURL client //Send request to https://zestframework.xyz login page with post method $request = $request->curl("https://zestframework.xyz/account/login/action","POST"); //Set transfer and return header $request->setReturnHeader(true)->setReturnTransfer(true); //Set the fields $request->setFields([

'username'  => 'your-username',
'password' => 'your-password'

]); //Send the request $request->send(); // return => 200 $statusCode = $request->getCode(); // Display the body of the returned response echo "<br\>".$request->getBody();













  Files folder image Files  
File Role Description
Files folder imageexample (1 file)
Files folder imagesrc (11 files, 1 directory)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file readme.md Doc. Readme

  Files folder image Files  /  example  
File Role Description
  Accessible without login Plain text file index.php Example Example script

  Files folder image Files  /  src  
File Role Description
Files folder imageClients (4 files)
  Plain text file Headers.php Class Class source
  Plain text file HTTP.php Class Class source
  Plain text file Message.php Class Class source
  Plain text file Redirect.php Class Class source
  Plain text file Request.php Class Class source
  Plain text file Response.php Class Class source
  Plain text file ServerRequest.php Class Class source
  Plain text file StatusCode.php Class Class source
  Plain text file UploadedFile.php Class Class source
  Plain text file Uri.php Class Class source
  Plain text file ValidProtocolVersions.php Class Class source

  Files folder image Files  /  src  /  Clients  
File Role Description
  Plain text file AbstractClient.php Class Class source
  Plain text file Client.php Class Class source
  Plain text file CURL.php Class Class source
  Plain text file Stream.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:160
This week:2
All time:8,961
This week:94Up