lithium\net\http\Service::send()
Send request and return response data. Will open the connection if needed and always close it after sending the request.
Will automatically authenticate when receiving a 401
HTTP status code
then continue retrying sending initial request.
Parameters
-
string
$method
-
string
$path
-
array
$data
the parameters for the request. For GET/DELETE this is the query string for POST/PUT this is the body
-
array
$options
passed to request and socket
Returns
stringSource
public function send($method, $path = null, $data = [], array $options = []) {
$defaults = ['return' => 'body'];
$options += $defaults;
$request = $this->_request($method, $path, $data, $options);
$options += ['message' => $request];
if (!$this->connection || !$this->connection->open($options)) {
return;
}
$response = $this->connection->send($request, $options);
$this->connection->close();
if ($response->status['code'] == 401 && ($auth = $response->digest())) {
$request->auth = $auth;
$this->connection->open(['message' => $request] + $options);
$response = $this->connection->send($request, $options);
$this->connection->close();
}
$this->last = (object) compact('request', 'response');
$handlers = $this->_responseTypes;
$handler = isset($handlers[$options['return']]) ? $handlers[$options['return']] : null;
return $handler ? $handler($response) : $response;
}