PHP code example of hitraa / openforge-curl

1. Go to this page and download the library: Download hitraa/openforge-curl 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/ */

    

hitraa / openforge-curl example snippets


use OpenForge\Curl\HttpRequest;

$response = (new HttpRequest('https://httpbin.org/get'))
    ->setMethod('GET')
    ->setData(['q' => 'openforge'])
    ->responseArray();

print_r($response);

$response = (new HttpRequest('https://httpbin.org/post'))
    ->setMethod('POST')
    ->setJson([
        'username' => 'harshal',
        'role' => 'admin'
    ])
    ->responseObject();

$response = (new HttpRequest('https://httpbin.org/post'))
    ->setMethod('POST')
    ->setRaw('<xml><user>Harshal</user></xml>')
    ->addHeader('Content-Type: application/xml')
    ->responseText();

$response = (new HttpRequest('https://api.example.com/secure'))
    ->setMethod('GET')
    ->setBearer('your-token-here')
    ->responseArray();

$response = (new HttpRequest('https://self-signed.local/api'))
    ->setMethod('GET')
    ->sslVerify(false) // ⚠️ disables certificate & hostname verification
    ->responseArray();

$response = (new HttpRequest('https://dev.api'))
    ->setMethod('GET')
    ->sslAuto(); // disables SSL if APP_ENV = local or testing

// Explicitly set APP_ENV
putenv("APP_ENV=local");

// Do https cURL request
$response = (new HttpRequest('https://dev.api'))
    ->setMethod('GET')

->sslAuto('MY_ENV', ['dev', 'staging'])

openforge-curl/
├── src/                  # Library source code
│   └── HttpRequest.php
├── tests/                # Unit tests
│   └── HttpRequestTest.php
├── composer.json
├── phpunit.xml
├── .gitignore
├── .gitattributes
└── README.md