PHP Classes
elePHPant
Icontem

HttpRequest: Send HTTP requests to remote servers

Recommend this page to a friend!
  Info   View files Example   View files View files (23)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2015-01-10 (1 year ago) RSS 2.0 feedNot enough user ratingsTotal: 448 All time: 5,886 This week: 1,099Up
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
Innovation award
Innovation award
Nominee: 2x

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  
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

 Version Control Unique User Downloads Download Rankings  
 100%
Total:448
This week:0
All time:5,886
This week:1,099Up