client::request()
Make an HTTP GET or POST request to a URL.
Prototype
response request(string $url, array $options = [])
Parameters
- url - URL to send request to.
- options - Same options as client::Constructor.
Return
A response object is returned. For details, see return for send().
Example
$url = 'https://demo.webcomand.com/ws/get';
$token = 'authentication-token-here';
$json = '{"query": "SELECT OID, Title FROM HelpDoc"}';
$response = \io_comand_web\client::request($url, [
'method' => 'post',
'headers' => [
"Authorization: Token $token"
],
'fields' => [
'query' => 'SELECT OID, Title FROM HelpDoc'
]
]);
if(!$response || !isset($response->info)) {
echo("Unexpected result.\n");
}
echo("Response Payload: " . $response->payload . "\n");
echo("Response HTTP Code: " . $response->info['http_code']);
// if the response was JSON
if(isset($response->data)) {
echo("JSON Data: " . print_r($response->data, TRUE));
}