webCOMAND

client::send()

Sends the prepared HTTP request to the URL specified in the client::Constructor.

Prototype

response send()

Return

A response object is returned with the following properties, even if there is an error or 404 response.  NULL or FALSE may be returned if there is a critical error that occurs before the request can be made, but in most cases a response object will be returned, at least with an error set.

  • headers - The response headers as an associative array where the key is the header name in all lowercase and the value is the trimmed header value.
  • payload - The raw response payload.
  • info - associative array returned by curl_getinfo().
  • data - If payload contains valid JSON data, this property will contain the result of json_decode(payload).  Otherwise, it will be NULL.
  • error - NULL if no error, otherwise a string with an error message.  This will be set only if the request could not be completed due to an SSL certificate error, timeout or other error that prevents a response from the destination.  Other errors, such as 404 responses will not produce this type of error, as there was a valid response.  Check the payload, info and data for those situations.
    If there is a timeout, error will be set, but info will also be populated with applicable values, including total_time.

Example

$url = 'https://demo.webcomand.com/ws/get';
$token = 'authentication-token-here';
$request = new \io_comand_web\client($url);
$request->method('post');
$request->headers = [
    "Content-Type: application/json",
    "Authorization: Token $token"
];
$request->body = '{"query": "SELECT OID, Title FROM HelpDoc"}';
$response = $request->send();
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));
}

Related

post(), request(), send()