client::encode()
Sets how to encode the fields of the HTTP client request.
Prototype
string encode(string $encoding)
Parameters
- encoding - One of the following encodings.
- auto (default)
- application/x-www-form-urlencoded
- multipart/form-data
Return
The previously set encoding, or FALSE if the encoding 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');
$request->encode('multipart/form-data');
$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));
}