PHP code example of srikant-kumar / simple-http-request

1. Go to this page and download the library: Download srikant-kumar/simple-http-request 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/ */

    

srikant-kumar / simple-http-request example snippets



Httprequest\Httprequest;
//---This Sample Code For POST Request
$request = new Httprequest('https://example.com');
$post_data = [
	'key1' => $value1,
	'key2' => $value2,
	'key3' => $value3,
];
$request_header = [
	'Authorization' => 'Bearer e5e87a27-3a33-4e03-b3c5-e31d82fdc2f3',
	'x-api-key' => 'mf2yEb92mzcXArFNh2QP7rfpyTS4hgT'
];
//----Options of Http Request
$request->set_content_type('multipart/form-data');
$request->set_request_method('POST');
$request->set_post_data($post_data);
//----Request Header If Needed
$request->set_request_headers($request_header);
$request->run();
$response = $request->get_response();


Httprequest\Httprequest;
//---This Sample Code For POST Request
$request = new Httprequest('https://example.com');
$post_data = [
	'key1' => $value1,
	'key2' => $value2,
	'key3' => $value3,
];
$request_header = [
	'Authorization' => 'Bearer e5e87a27-3a33-4e03-b3c5-e31d82fdc2f3',
	'x-api-key' => 'mf2yEb92mzcXArFNh2QP7rfpyTS4hgT'
];
//----Options of Http Request
$request->set_content_type('multipart/form-data');
$request->set_request_method('POST');
$request->set_post_data($post_data);
//----Request Header If Needed
$request->set_request_headers($request_header);
$request->run();
$response = $request->get_response();
$request->set_request_method('POST');
$request->set_request_headers($request_header);
$request->set_user_agent($user_agent);
$request->enable_cookies($cookie_file_path);
$request->set_timeout($time);
$request->run();
$request->get_response_header();
$request->get_response_header_array();
$request->get_http_code();
$request->get_excution_time($unit='ms');
$request->get_error();