lithium\net\http\Service::send PHP Method

send() public method

Will automatically authenticate when receiving a 401 HTTP status code then continue retrying sending initial request.
public send ( string $method, string $path = null, array $data = [], array $options = [] ) : string
$method string
$path string
$data array the parameters for the request. For GET/DELETE this is the query string for POST/PUT this is the body
$options array passed to request and socket
return string
    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');
        $handlers = $this->_responseTypes;
        $handler = isset($handlers[$options['return']]) ? $handlers[$options['return']] : null;
        return $handler ? $handler($response) : $response;
    }

Usage Example

 public function send($method, $path = null, $data = array(), array $options = array())
 {
     $defaults = array('headers' => array('User-Agent' => 'Lava Surfboard'));
     $xml = new \SimpleXmlElement('<request method="' . $path . '"></request>');
     foreach ($data as $key => $val) {
         if ($val != null) {
             $xml->{$key} = $val;
         }
     }
     $xmlString = $xml->asXML();
     $data = str_replace("<?xml version=\"1.0\"?>\n", '<!--?xml version="1.0" encoding="utf-8"?-->', $xmlString);
     $path = '/api/2.1/xml-in';
     $response = parent::send($method, $path, $data, $options + $defaults);
     return new \SimpleXmlElement($response);
 }
All Usage Examples Of lithium\net\http\Service::send