SFAPIclient/Requests.php
public static function request($url, $headers = array(), $data = array(), $type = self::GET, $options = array()) {
		if (!preg_match('/^http(s)?:\/\//i', $url)) {
			throw new Requests_Exception('Only HTTP requests are handled.', 'nonhttp', $url);
		}
		$defaults = array(
			'timeout' => 10,
			'useragent' => 'php-requests/' . self::VERSION,
			'redirected' => 0,
			'redirects' => 10,
			'follow_redirects' => true,
			'blocking' => true,
			'type' => $type,
			'filename' => false,
			'auth' => false,
			'idn' => true,
			'hooks' => null,
			'transport' => null,
		);
		$options = array_merge($defaults, $options);

		if (empty($options['hooks'])) {
			$options['hooks'] = new Requests_Hooks();
		}

		// Special case for simple basic auth
		if (is_array($options['auth'])) {
			$options['auth'] = new Requests_Auth_Basic($options['auth']);
		}
		if ($options['auth'] !== false) {
			$options['auth']->register($options['hooks']);
		}

		$options['hooks']->dispatch('requests.before_request', array(&$url, &$headers, &$data, &$type, &$options));

		if ($options['idn'] !== false) {
			$iri = new Requests_IRI($url);
			$iri->host = Requests_IDNAEncoder::encode($iri->ihost);
			$url = $iri->uri;
		}

		if (!empty($options['transport'])) {
			$transport = $options['transport'];

			if (is_string($options['transport'])) {
				$transport = new $transport();
			}
		}
		else {
			$transport = self::get_transport();
		}
		$response = $transport->request($url, $headers, $data, $options);

		$options['hooks']->dispatch('requests.before_parse', array(&$response, $url, $headers, $data, $type, $options));

		return self::parse_response($response, $url, $headers, $data, $options);
	}
public static function request($url, $headers = array(), $data = array(), $type = self::GET, $options = array()) {
		if (!preg_match('/^http(s)?:\/\//i', $url)) {
			throw new Requests_Exception('Only HTTP requests are handled.', 'nonhttp', $url);
		}
		$defaults = array(
			'timeout' => 10,
			'useragent' => 'php-requests/' . self::VERSION,
			'redirected' => 0,
			'redirects' => 10,
			'follow_redirects' => true,
			'blocking' => true,
			'type' => $type,
			'filename' => false,
			'auth' => false,
			'idn' => true,
			'hooks' => null,
			'transport' => null,
		);
		$options = array_merge($defaults, $options);

		if (empty($options['hooks'])) {
			$options['hooks'] = new Requests_Hooks();
		}

		// Special case for simple basic auth
		if (is_array($options['auth'])) {
			$options['auth'] = new Requests_Auth_Basic($options['auth']);
		}
		if ($options['auth'] !== false) {
			$options['auth']->register($options['hooks']);
		}

		$options['hooks']->dispatch('requests.before_request', array(&$url, &$headers, &$data, &$type, &$options));

		if ($options['idn'] !== false) {
			$iri = new Requests_IRI($url);
			$iri->host = Requests_IDNAEncoder::encode($iri->ihost);
			$url = $iri->uri;
		}

		if (!empty($options['transport'])) {
			$transport = $options['transport'];

			if (is_string($options['transport'])) {
				$transport = new $transport();
			}
		}
		else {
			$transport = self::get_transport();
		}
		$response = $transport->request($url, $headers, $data, $options);

		$options['hooks']->dispatch('requests.before_parse', array(&$response, $url, $headers, $data, $type, $options));

		return self::parse_response($response, $url, $headers, $data, $options);
	}
public static function request ( $ url , $ headers = array ( ) , $ data = array ( ) , $ type = self :: GET , $ options = array ( ) ) { if ( ! preg_match ( '/^http(s)?:\/\//i' , $ url ) ) { throw new Requests_Exception ( 'Only HTTP requests are handled.' , 'nonhttp' , $ url ) ; } $ defaults = array ( 'timeout' => 10 , 'useragent' => 'php-requests/' . self :: VERSION , 'redirected' => 0 , 'redirects' => 10 , 'follow_redirects' => true , 'blocking' => true , 'type' => $ type , 'filename' => false , 'auth' => false , 'idn' => true , 'hooks' => null , 'transport' => null , ) ; $ options = array_merge ( $ defaults , $ options ) ; if ( empty ( $ options [ 'hooks' ] ) ) { $ options [ 'hooks' ] = new Requests_Hooks ( ) ; } // Special case for simple basic auth if ( is_array ( $ options [ 'auth' ] ) ) { $ options [ 'auth' ] = new Requests_Auth_Basic ( $ options [ 'auth' ] ) ; } if ( $ options [ 'auth' ] !== false ) { $ options [ 'auth' ] -> register ( $ options [ 'hooks' ] ) ; } $ options [ 'hooks' ] -> dispatch ( 'requests.before_request' , array ( & $ url , & $ headers , & $ data , & $ type , & $ options ) ) ; if ( $ options [ 'idn' ] !== false ) { $ iri = new Requests_IRI ( $ url ) ; $ iri -> host = Requests_IDNAEncoder :: encode ( $ iri -> ihost ) ; $ url = $ iri -> uri ; } if ( ! empty ( $ options [ 'transport' ] ) ) { $ transport = $ options [ 'transport' ] ; if ( is_string ( $ options [ 'transport' ] ) ) { $ transport = new $ transport ( ) ; } } else { $ transport = self :: get_transport ( ) ; } $ response = $ transport -> request ( $ url , $ headers , $ data , $ options ) ; $ options [ 'hooks' ] -> dispatch ( 'requests.before_parse' , array ( & $ response , $ url , $ headers , $ data , $ type , $ options ) ) ; return self :: parse_response ( $ response , $ url , $ headers , $ data , $ options ) ; }
Main interface for HTTP requests

This method initiates a request and sends it via a transport before
parsing.

The `$options` parameter takes an associative array with the following
options:

- `timeout`: How long should we wait for a response?
(integer, seconds, default: 10)
- `useragent`: Useragent to send to the server
(string, default: php-requests/$version)
- `follow_redirects`: Should we follow 3xx redirects?
(boolean, default: true)
- `redirects`: How many times should we redirect before erroring?
(integer, default: 10)
- `blocking`: Should we block processing on this request?
(boolean, default: true)
- `filename`: File to stream the body to instead.
(string|boolean, default: false)
- `auth`: Authentication handler or array of user/password details to use
for Basic authentication
(Requests_Auth|array|boolean, default: false)
- `idn`: Enable IDN parsing
(boolean, default: true)
- `transport`: Custom transport. Either a class name, or a
transport object. Defaults to the first working transport from
{@see getTransport()}
(string|Requests_Transport, default: {@see getTransport()})

@throws Requests_Exception On invalid URLs (`nonhttp`)

@param string $url URL to request
@param array $headers Extra headers to send with the request
@param array $data Data to send either as a query string for GET/HEAD requests, or in the body for POST requests
@param string $type HTTP request type (use Requests constants)
@param array $options Options for the request (see description for more information)
@return Requests_Response
Main interface for HTTP requests