Amiro.CMS API Reference
Amiro.Ru / Manual
Loading search...

The AMI_HTTPRequest class

• Introduction

HTTP request class.

• Class synopsis

AMI_HTTPRequest {
/* Constants */
// HTTP GET request method
const AMI_HTTPRequest::METHOD_GET =  1;
// HTTP POST request method
const AMI_HTTPRequest::METHOD_POST =  2;
/* Properties */
// HTTP Request settings
protected array $aSettings = array();
/* Methods */
// Constructor.
public __construct ( [ $aSettings = array() ] ) returns AMI_HTTPRequest;
// Set new settings.
public alterSettings ( [ $aSettings = array() ] ) returns void;
// Returns CURL error.
public getError ( ) returns array;
// Returns CURL info.
public getInfo ( ) returns array;
// Send HTTP request and returns the result.
public send ( string $url, [ $aData = array() ], [ int $method = self::METHOD_GET ] ) returns string;
}

• Class Details

Allows to execute GET or POST HTTP requests.

  Example:
  •  require_once 'ami_env.php';
  •  $oHTTPRequest new AMI_HTTPRequest();
  •  $oHTTPRequest->send('http://anysite'array('postVar' => 'value')AMI_HTTPRequest::METHOD_POST);
Tags:
since 5.12.4

• Class Constants

METHOD_GET

HTTP GET request method

METHOD_POST

HTTP POST request method

• Class Properies

protected array $aSettings

HTTP Request settings

• Class Methods

// Constructor.
public __construct ( [ $aSettings = array() ] ) returns AMI_HTTPRequest;
  • array $aSettings
    Settings array
  Example:
  •  $oHTTPRequest new AMI_HTTPRequest(
  •      array(
  •          'returnHeaders'  => FALSE,  // Specifies to return headers if TRUE, bool, FALSE by default
  •          'followLocation' => TRUE,   // Follow the redirects if TRUE, bool, TRUE by default
  •          'useCookies'     => FALSE,  // Allow to receive cookies, bool, FALSE by default
  •          'userAgent'      => '',     // User Agent, string, 'AMI_HTTPRequest' by default
  •          'cookieFile'     => '',     // Name of the cookie file, string, empty string by default
  •          'verifySSL'      => FALSE,  // Verify SSL certificate (since 6.0.4)
  •          'referer'        => ''      // Referer (since 7.0.0)
  •      )
  •  );
// Set new settings.
public alterSettings ( [ $aSettings = array() ] ) returns void;
  • array $aSettings
    Settings array
// Returns CURL error.
public getError ( ) returns array;
Tags:
since 6.0.2
// Returns CURL info.
public getInfo ( ) returns array;
Tags:
see curl_getinfo()
since 6.0.2
// Send HTTP request and returns the result.
public send ( string $url, [ $aData = array() ], [ int $method = self::METHOD_GET ] ) returns string;
  • string $url
    Request URL
  • array $aData
    Associative array containing request data
  • int $method
    HTTP requset method: AMI_HTTPRequest::METHOD_GET, AMI_HTTPRequest::METHOD_POST