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

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