Beispiel #1
0
 public static function fileGetContent($url, $exceptions = false)
 {
     try {
         $request = new Customweb_Http_Request($url);
         $response = $request->send();
         if ($response->getStatusCode() != 200) {
             throw new Exception($response->getStatusCode() . ': ' . $response->getStatusMessage());
         }
         return $response->getBody();
     } catch (Exception $e) {
         if ($exceptions) {
             throw $e;
         }
         return false;
     }
 }
Beispiel #2
0
 /**
  * Sends a request to one of the Saferpay service urls. We do some
  * basic response validation here already.
  *         	   		  	 	 	
  * @param string $url
  */
 public static function sendRequest($url, $method = "GET", $postParams = null)
 {
     $handler = new Customweb_Http_Response();
     $request = new Customweb_Http_Request($url);
     $request->setResponseHandler($handler)->setMethod($method)->setBody($postParams)->send();
     if ($handler->getStatusCode() != 200) {
         throw new Exception('Saferpay Server response is: ' . $handler->getStatusCode() . ' ' . $handler->getStatusMessage());
     }
     $response = trim($handler->getBody());
     $pos = strpos($response, ':');
     if ($pos === false) {
         return $response;
     }
     $result = substr($response, 0, $pos);
     $data = substr($response, $pos + 1);
     if ($result != 'OK' && $result != 'ERROR') {
         return $response;
     }
     if ($result == 'ERROR') {
         throw new Exception(Customweb_I18n_Translation::__("An error occured: Saferpay response is: '!data'", array('!data' => trim($data))));
     }
     return $data;
 }