Send request and return response data.

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

string

Source

						public function send($method, $path = null, $data = array(), array $options = array()) {
		$defaults = array('return' => 'body');
		$options += $defaults;
		$request = $this->_request($method, $path, $data, $options);
		$options += array('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(array('message' => $request) + $options);
			$response = $this->connection->send($request, $options);
			$this->connection->close();
		}
		$this->last = (object) compact('request', 'response');
		return ($options['return'] == 'body' && $response) ? $response->body() : $response;
	}