Skip to content

abdelhak-elhadidy/curl-php-request

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

curl-php-request

PHP cURL GET request and request's body PHP cUrl Class makes it easy to send HTTP requests and integrate with web APIs.

Requirements

PHP Curl Class works with PHP 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, and 8.1.

Installation

To Import PHP Curl Class:

require_once( dirname(__FILE__) . '/HTTPRequester.php' );

Quick Start and Examples

To Send GET Request:

HTTPRequester::HTTPGet($target_url, $params);

To Send POST Request:

HTTPRequester::HTTPPost($target_url, $data, $header, false);

To Send PUT Request:

HTTPRequester::HTTPPut($target_url, $params);

To Send DELETE Request:

HTTPRequester::HTTPDelete($target_url, $params);

Example

require_once( dirname(__FILE__) . '/HTTPRequester.php' );

$target_url = "http://localhost/upload";
$fname = 'D:\1.MP4';
$cfile = new CURLFile(realpath($fname));
$data = array(
    'file' => $cfile
);

$header = array(
    'Content-Type: multipart/form-data'
);

$result = (HTTPRequester::HTTPPost($target_url, $data, $header, false));

if ($result === FALSE) {
    echo "Error sending" . $fname;
} else {
    echo "Result: " . $result;
}

About

PHP cURL GET request and request's body

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages