PHP code example of hedii / http-punch

1. Go to this page and download the library: Download hedii/http-punch library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hedii / http-punch example snippets




// /path/to/vendor/autoload.php';

// instantiate
$puncher = new Hedii\HttpPunch\HttpPunch();

// instantiate with request and connection timeout as parameters
$puncher = new Hedii\HttpPunch\HttpPunch(20, 5);

// instantiate
$puncher = new Hedii\HttpPunch\HttpPunch();

// perform a get request
$result = $puncher->punch('http://example.com');

// perform a post request 
$result = $puncher->punch('http://example.com', 'post');

// perform a post request with a given body as an array
$result = $puncher->punch('http://example.com', 'post', ['foo' => 'bar']);

// set the outgoing ip address (it uses CURLOPT_INTERFACE behind the scenes) and perform a get request
$result = $puncher->setIp('192.160.0.101')->punch('http://example.com');

// set an array of request headers and perform a get request
$result = $puncher->setHeaders(['foo' => 'bar'])->punch('http://example.com');