示例#1
0
 /**
  * Send an NCIP request.
  *
  * @param string $xml XML request document
  *
  * @return object     SimpleXMLElement parsed from response
  */
 protected function sendRequest($xml)
 {
     // Make the NCIP request:
     try {
         $client = new HttpClient();
         $client->setUri($this->config['Catalog']['url']);
         $client->setParameterPost(array('NCIP' => $xml));
         $result = $client->setMethod('POST')->send();
     } catch (\Exception $e) {
         throw new ILSException($e->getMessage());
     }
     if (!$result->isSuccess()) {
         throw new ILSException('HTTP error');
     }
     // Process the NCIP response:
     $response = $result->getBody();
     if ($result = @simplexml_load_string($response)) {
         return $result;
     } else {
         throw new ILSException("Problem parsing XML");
     }
 }
示例#2
0
 /**
  * Support method -- perform an HTTP request.  This will be a GET request unless
  * either $postParams or $rawPost is set to a non-null value.
  *
  * @param string $url        Target URL for request
  * @param array  $postParams Associative array of POST parameters (null for
  * none).
  * @param string $rawPost    String representing raw POST parameters (null for
  * none).
  *
  * @throws ILSException
  * @return string Response body
  */
 protected function httpRequest($url, $postParams = null, $rawPost = null)
 {
     $method = is_null($postParams) && is_null($rawPost) ? 'GET' : 'POST';
     try {
         $client = new HttpClient();
         $client->setUri($url);
         if (is_array($postParams)) {
             $client->setParameterPost($postParams);
         }
         if (!is_null($rawPost)) {
             $client->setRawBody($rawPost);
             $client->setEncType('application/x-www-form-urlencoded');
         }
         $result = $client->setMethod($method)->send();
     } catch (\Exception $e) {
         throw new ILSException($e->getMessage());
     }
     if (!$result->isSuccess()) {
         throw new ILSException('HTTP error');
     }
     return $result->getBody();
 }