PHP Classes

HttpRequest: Send HTTP requests to remote servers

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStar 56%Total: 469 All time: 6,030 This week: 455Up
Version License PHP version Categories
http-request 1.0.0BSD License5.5Networking, HTTP, PHP 5
Description 

Author

This package can send HTTP requests to remote servers.

It provides several classes for sending HTTP GET or POST requests with support for file uploading using form POST requests.

A separate class can be used to configure several aspects of the HTTP request to be sent like the content type or other request headers.

Picture of Gonzalo Chumillas
Name: Gonzalo Chumillas <contact>
Classes: 8 packages by
Country: Spain Spain
Age: 50
All time rank: 135129 in Spain Spain
Week rank: 195 Up7 in Spain Spain Up
Innovation award
Innovation award
Nominee: 2x

Example

<?php
header
("Content-Type: text/plain; charset=UTF-8");
require_once
"../classes/autoload.php";
use
com\soloproyectos\common\http\request\HttpRequestConfig;
use
com\soloproyectos\common\http\request\HttpRequestFormFile;
use
com\soloproyectos\common\http\request\HttpRequestPost;

// configuration
$config = new HttpRequestConfig();
$config->setContentTypeOption("charset", "iso-8859-1");

// sends a POST request to receiver.php and prints the contents
$req = new HttpRequestPost($config);
$req->setParam("username", "john");
$req->setParam("password", "123456");
$req->setFormParam("image", new HttpRequestFormFile("image.jpg"));
echo
$req->send("http://$_SERVER[HTTP_HOST]/" . basename(__DIR__) . "/receiver.php");


Details

php.httprequest

A library for sending HTTP requests from the server side.

Installation

Download the project:

git clone https://github.com/soloproyectos/php.httprequest

and copy the classes folder in your preferred location (optionally, rename it). Finally, copy and paste the following PHP code:

require_once "< YOUR PREFERRED LOCATION >/classes/autoload.php";

Examples

Send a GET request

require_once "classes/autoload.php";
use com\soloproyectos\common\http\request\HttpRequestGet;

// sends a GET request to mysite.com
$req = new HttpRequestGet();
$req->setParam("username", "john");
$req->setParam("passwrod", "smith");
echo $req->send("http://www.mysite.com");

Send a POST request

require_once "classes/autoload.php";
use com\soloproyectos\common\http\request\HttpRequestFormFile;
use com\soloproyectos\common\http\request\HttpRequestPost;

// sends a POST request to mysite.com and attaches some files
$req = new HttpRequestPost();
$req->setParam("action", "upload-image");
$req->setFormParam("image", new HttpRequestFormFile("/path/to/image.jpg"));
echo $req->send("http://www.mysite.com");

Use a configuration object

require_once "classes/autoload.php";
use com\soloproyectos\common\http\request\HttpRequestConfig;
use com\soloproyectos\common\http\request\HttpRequestFormFile;
use com\soloproyectos\common\http\request\HttpRequestPost;

// in this case we use a configuration object
$config = new HttpRequestConfig();
$config->setOption("follow_location", true);
$config->setOption("user_agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36");
$config->setContentTypeOption("charset", "iso-8859-1");

// sends a POST request to mysite.com and attaches some files
$req = new HttpRequestPost($config);
$req->setParam("action", "upload-image");
$req->setFormParam("image", new HttpRequestFormFile("/path/to/image.jpg"));
echo $req->send("http://www.mysite.com");

  Files folder image Files (23)  
File Role Description
Files folder imageclasses (1 file, 3 directories)
Files folder imagetest (3 files)
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (23)  /  classes  
File Role Description
Files folder imagearr (1 file, 1 directory)
Files folder imagehttp (1 file, 2 directories)
Files folder imagetext (1 file, 3 directories)
  Accessible without login Plain text file autoload.php Class Class source

  Files folder image Files (23)  /  classes  /  arr  
File Role Description
Files folder imagearguments (2 files)
  Accessible without login Plain text file arr-helper.php Class Class source

  Files folder image Files (23)  /  classes  /  arr  /  arguments  
File Role Description
  Accessible without login Plain text file arr-arguments-descriptor.php Class Class source
  Accessible without login Plain text file arr-arguments.php Class Class source

  Files folder image Files (23)  /  classes  /  http  
File Role Description
Files folder imageexception (1 file)
Files folder imagerequest (6 files, 1 directory)
  Accessible without login Plain text file http-helper.php Class Class source

  Files folder image Files (23)  /  classes  /  http  /  exception  
File Role Description
  Accessible without login Plain text file http-exception.php Class Class source

  Files folder image Files (23)  /  classes  /  http  /  request  
File Role Description
Files folder imageexception (1 file)
  Accessible without login Plain text file http-request-abstract.php Class Class source
  Accessible without login Plain text file http-request-config.php Class Class source
  Accessible without login Plain text file http-request-form-data.php Class Class source
  Accessible without login Plain text file http-request-form-file.php Class Class source
  Accessible without login Plain text file http-request-get.php Class Class source
  Accessible without login Plain text file http-request-post.php Class Class source

  Files folder image Files (23)  /  classes  /  http  /  request  /  exception  
File Role Description
  Accessible without login Plain text file http-request-exception.php Class Class source

  Files folder image Files (23)  /  classes  /  text  
File Role Description
Files folder imageexception (1 file)
Files folder imageparser (1 file, 1 directory)
Files folder imagetokenizer (1 file)
  Accessible without login Plain text file text-helper.php Class Class source

  Files folder image Files (23)  /  classes  /  text  /  exception  
File Role Description
  Accessible without login Plain text file text-exception.php Class Class source

  Files folder image Files (23)  /  classes  /  text  /  parser  
File Role Description
Files folder imageexception (1 file)
  Accessible without login Plain text file text-parser.php Class Class source

  Files folder image Files (23)  /  classes  /  text  /  parser  /  exception  
File Role Description
  Accessible without login Plain text file text-parser-exception.php Class Class source

  Files folder image Files (23)  /  classes  /  text  /  tokenizer  
File Role Description
  Accessible without login Plain text file text-tokenizer.php Class Class source

  Files folder image Files (23)  /  test  
File Role Description
  Accessible without login Image file image.jpg Icon Icon image
  Accessible without login Plain text file receiver.php Aux. Example script
  Accessible without login Plain text file sender.php Example Example script

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:469
This week:0
All time:6,030
This week:455Up
 User Ratings  
 
 All time
Utility:75%StarStarStarStar
Consistency:66%StarStarStarStar
Documentation:58%StarStarStar
Examples:66%StarStarStarStar
Tests:-
Videos:-
Overall:56%StarStarStar
Rank:1792