/** * 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->setRawBody($xml); $client->setEncType('application/xml; "charset=utf-8"'); $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(); $result = @simplexml_load_string($response); if (is_a($result, 'SimpleXMLElement')) { $result->registerXPathNamespace('ns1', 'http://www.niso.org/2008/ncip'); return $result; } else { throw new ILSException("Problem parsing XML"); } }
/** * 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(); }
/** * Send a request to the SIRSI side API script and returns the response. * * @param array $params Associative array of query parameters to send. * * @return string */ protected function querySirsi($params) { // make sure null parameters are sent as empty strings instead or else the // driver.pl may choke on null parameter values foreach ($params as $key => $value) { if ($value == null) { $params[$key] = ''; } } $url = $this->url; if (empty($url)) { $url = $this->host; if ($this->port) { $url = "http://" . $url . ":" . $this->port . "/" . $this->search_prog; } else { $url = "http://" . $url . "/" . $this->search_prog; } } $httpClient = new HttpClient(); $httpClient->setMethod('POST'); $httpClient->setUri($url); $httpClient->setRawBody(http_build_query($params)); $httpClient->setEncType('application/x-www-form-urlencoded'); // use HTTP POST so parameters like user id and PIN are NOT logged by web // servers $result = $httpClient->send(); // Even if we get a response, make sure it's a 'good' one. if (!$result->isSuccess()) { throw new ILSException("Error response code received from {$url}"); } // get the response data $response = $result->getBody(); return rtrim($response); }