client::method()
Sets the HTTP method for the client request.
Prototype
string method(string $method)
Parameters
- method - 'get' or 'post'
Return
The previously set method, or FALSE if the method is invalid.
Example
$url = 'https://demo.webcomand.com/ws/get';
$token = 'authentication-token-here';
$request = new \io_comand_web\client($url);
$request->headers = [
"Content-Type: application/json",
"Authorization: Token $token"
];
$request->method('post');
$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
encode()