Exemplo n.º 1
0
 /**
  * Perform an XML-RPC request and return a response.
  *
  * @param Zend\XmlRpc\Request $request
  * @param null|Zend\XmlRpc\Response $response
  * @return void
  * @throws Zend\XmlRpc\Client\HttpException
  */
 public function doRequest($request, $response = null)
 {
     $this->_lastRequest = $request;
     iconv_set_encoding('input_encoding', 'UTF-8');
     iconv_set_encoding('output_encoding', 'UTF-8');
     iconv_set_encoding('internal_encoding', 'UTF-8');
     $http = $this->getHttpClient();
     $httpRequest = $http->getRequest();
     if ($httpRequest->getUri() === null) {
         $http->setUri($this->_serverAddress);
     }
     $headers = $httpRequest->headers();
     $headers->addHeaders(array('Content-Type: text/xml; charset=utf-8', 'Accept: text/xml'));
     if (!$headers->get('user-agent')) {
         $headers->addHeaderLine('user-agent', 'Zend_XmlRpc_Client');
     }
     $xml = $this->_lastRequest->__toString();
     $http->setRawBody($xml);
     $httpResponse = $http->setMethod('post')->send();
     if (!$httpResponse->isSuccess()) {
         /**
          * Exception thrown when an HTTP error occurs
          */
         throw new Client\Exception\HttpException($httpResponse->getReasonPhrase(), $httpResponse->getStatusCode());
     }
     if ($response === null) {
         $response = new Response();
     }
     $this->_lastResponse = $response;
     $this->_lastResponse->loadXml($httpResponse->getBody());
 }
Exemplo n.º 2
0
 /**
  * Perform an XML-RPC request and return a response.
  *
  * @param Zend\XmlRpc\Request $request
  * @param null|Zend\XmlRpc\Response $response
  * @return void
  * @throws Zend\XmlRpc\Client\HTTPException
  */
 public function doRequest($request, $response = null)
 {
     $this->_lastRequest = $request;
     iconv_set_encoding('input_encoding', 'UTF-8');
     iconv_set_encoding('output_encoding', 'UTF-8');
     iconv_set_encoding('internal_encoding', 'UTF-8');
     $http = $this->getHttpClient();
     if ($http->getUri() === null) {
         $http->setUri($this->_serverAddress);
     }
     $http->setHeaders(array('Content-Type: text/xml; charset=utf-8', 'Accept: text/xml'));
     if ($http->getHeader('user-agent') === null) {
         $http->setHeaders(array('User-Agent: Zend_XmlRpc_Client'));
     }
     $xml = $this->_lastRequest->__toString();
     $http->setRawData($xml);
     $httpResponse = $http->request(HTTP\Client::POST);
     if (!$httpResponse->isSuccessful()) {
         /**
          * Exception thrown when an HTTP error occurs
          */
         throw new Client\HTTPException($httpResponse->getMessage(), $httpResponse->getStatus());
     }
     if ($response === null) {
         $response = new Response();
     }
     $this->_lastResponse = $response;
     $this->_lastResponse->loadXml($httpResponse->getBody());
 }