/** * Send a request and get a response. * * @param \Hoa\XmlRpc\Message\Request $message Message. * @return \Hoa\XmlRpc\Message\Response * @throws \Hoa\XmlRpc\Exception\Fault */ public function send(Message\Request $message) { $request = $message->__toString(); $this->_client->writeAll($this->getHeader($request)); $response = $this->_client->readAll(); if (false === ($pos = strpos($response, "\r\n\r\n"))) { throw new Exception('Oops, an unknown error occured. Headers seem to be corrupted.', 0); } $response = substr($response, $pos + 4); if (0 !== preg_match('#<methodResponse>(\\s|\\n)*<fault>#i', $response)) { preg_match('#<(i4|int)>(?:\\s|\\n)*(\\d+)(?:\\s|\\n)*</\\1>#i', $response, $faultCodeMatches); preg_match('#<string>(?:\\s|\\n)*(.*)(?:\\s|\\n)*</string>#i', $response, $faultStringMatches); $faultCode = -1; $faultString = 'An ununderstable fault from the server occured.'; if (isset($faultCodeMatches[2])) { $faultCode = $faultCodeMatches[2]; } if (isset($faultStringMatches[1])) { $faultString = $faultStringMatches[1]; } throw new Exception\Fault($faultString, $faultCode, $request); } return new Message\Response($response); }