webCOMAND

io_comand_web\client

Class used to build and make HTTP requests using PHP cURL, and return the response in more convenient format.

Form POST Example

The following example will POST simple login form values to a login service and display the response headers and payload.

// HTTP POST request to login.
$url = 'https://demo.webcomand.com/ws/login';
$response = \io_comand_web\client::post($url, [
    'fields' => [
        'Username' => 'Test',
        'Password' => '1234'
    ]
]);
if(!$response) {
    echo('Unknown error making request.');
}
echo('Response Info: ' . print_r($response->info, TRUE));
echo('Response Payload: ' . $response->payload);

JSON POST Example

The following example will POST a simple Get Web Service request and display the result status.

// HTTP JSON POST request.
$url = 'https://demo.webcomand.com/ws/get';
$response = \io_comand_web\client::post($url, [
    'body' => '{"token": "123", "query": "FROM HelpDocURL"}'
]);
if(!$response || !isset($response->data)) {
    echo('Unexpected error making JSON request.');
}
if($response->data->Result != 'OK') {
    echo('Query Error: ' . $response->data->Message); 
}
foreach($response->data->contents as $object) {
   echo($object->Title . "\n");
}