ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
XML_RPC2_Util_HTTPRequest Class Reference
+ Collaboration diagram for XML_RPC2_Util_HTTPRequest:

Public Member Functions

 getBody ()
 body field getter More...
 
 setPostData ($value)
 postData field setter More...
 
 __construct ($uri='', $params=array())
 Constructor. More...
 
 sendRequest ()
 Sends the request. More...
 

Private Attributes

 $_proxy = null
 
 $_proxyAuth = null
 
 $_postData
 
 $_uri
 
 $_encoding ='iso-8859-1'
 
 $_sslverify =true
 

Detailed Description

Definition at line 58 of file HTTPRequest.php.

Constructor & Destructor Documentation

◆ __construct()

XML_RPC2_Util_HTTPRequest::__construct (   $uri = '',
  $params = array() 
)

Constructor.

Sets up the object

Parameters
stringThe uri to fetch/access
arrayAssociative array of parameters which can have the following keys:
  • proxy - Proxy (string)
  • encoding - The request encoding (string)
@access public

Definition at line 146 of file HTTPRequest.php.

147 {
148 if (!preg_match('/(https?:\/\/)(.*)/', $uri)) throw new XML_RPC2_Exception('Unable to parse URI');
149 $this->_uri = $uri;
150 if (isset($params['encoding'])) {
151 $this->_encoding = $params['encoding'];
152 }
153 if (isset($params['proxy'])) {
154 $proxy = $params['proxy'];
155 $elements = parse_url($proxy);
156 if (is_array($elements)) {
157 if ((isset($elements['scheme'])) and (isset($elements['host']))) {
158 $this->_proxy = $elements['scheme'] . '://' . $elements['host'];
159 }
160 if (isset($elements['port'])) {
161 $this->_proxy = $this->_proxy . ':' . $elements['port'];
162 }
163 if ((isset($elements['user'])) and (isset($elements['pass']))) {
164 $this->_proxyAuth = $elements['user'] . ':' . $elements['pass'];
165 }
166 }
167 }
168 if (isset($params['sslverify'])) {
169 $this->_sslverify = $params['sslverify'];
170 }
171 }
$params
Definition: example_049.php:96

References $params.

Member Function Documentation

◆ getBody()

XML_RPC2_Util_HTTPRequest::getBody ( )

body field getter

Returns
string body value

Definition at line 113 of file HTTPRequest.php.

114 {
115 return $this->_body;
116 }

◆ sendRequest()

XML_RPC2_Util_HTTPRequest::sendRequest ( )

Sends the request.

@access public

Returns
mixed PEAR error on error, true otherwise

Definition at line 182 of file HTTPRequest.php.

183 {
184 if (!function_exists('curl_init') &&
185 !( // TODO Use PEAR::loadExtension once PEAR passes PHP5 unit tests (E_STRICT compliance, namely)
186 @dl('php_curl' . PHP_SHLIB_SUFFIX) || @dl('curl' . PHP_SHLIB_SUFFIX)
187 )) {
188 throw new XML_RPC2_CurlException('cURI extension is not present and load failed');
189 }
190 if ($ch = curl_init()) {
191 if (
192 (is_null($this->_proxy) || curl_setopt($ch, CURLOPT_PROXY, $this->_proxy)) &&
193 (is_null($this->_proxyAuth) || curl_setopt($ch, CURLOPT_PROXYUSERPWD, $this->_proxyAuth)) &&
194 curl_setopt($ch, CURLOPT_URL, $this->_uri) &&
195 curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE) &&
196 curl_setopt($ch, CURLOPT_POST, 1) &&
197 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->_sslverify) &&
198 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: text/xml; charset='.$this->_encoding, 'User-Agent: PEAR_XML_RCP2/' . XML_RPC2_Client::VERSION)) &&
199 curl_setopt($ch, CURLOPT_POSTFIELDS, $this->_postData)
200 ) {
201 $result = curl_exec($ch);
202 if (($errno = curl_errno($ch)) != 0) {
203 throw new XML_RPC2_CurlException("Curl returned non-null errno $errno:" . curl_error($ch));
204 }
205 $info = curl_getinfo($ch);
206 if ($info['http_code'] != 200) {
207 throw new XML_RPC2_ReceivedInvalidStatusCodeException('Curl returned non 200 HTTP code: ' . $info['http_code'] . '. Response body:' . $result);
208 }
209 } else {
210 throw new XML_RPC2_CurlException('Unable to setup curl');
211 }
212 } else {
213 throw new XML_RPC2_CurlException('Unable to init curl');
214 }
215 $this->_body = $result;
216 return true;
217 }
$result
const VERSION
Definition: Client.php:74
$info
Definition: example_052.php:80

References $info, $result, and XML_RPC2_Client\VERSION.

◆ setPostData()

XML_RPC2_Util_HTTPRequest::setPostData (   $value)

postData field setter

Parameters
stringpostData value

Definition at line 126 of file HTTPRequest.php.

127 {
128 $this->_postData = $value;
129 }

Field Documentation

◆ $_encoding

XML_RPC2_Util_HTTPRequest::$_encoding ='iso-8859-1'
private

Definition at line 96 of file HTTPRequest.php.

◆ $_postData

XML_RPC2_Util_HTTPRequest::$_postData
private

Definition at line 82 of file HTTPRequest.php.

◆ $_proxy

XML_RPC2_Util_HTTPRequest::$_proxy = null
private

Definition at line 68 of file HTTPRequest.php.

◆ $_proxyAuth

XML_RPC2_Util_HTTPRequest::$_proxyAuth = null
private

Definition at line 75 of file HTTPRequest.php.

◆ $_sslverify

XML_RPC2_Util_HTTPRequest::$_sslverify =true
private

Definition at line 103 of file HTTPRequest.php.

◆ $_uri

XML_RPC2_Util_HTTPRequest::$_uri
private

Definition at line 89 of file HTTPRequest.php.


The documentation for this class was generated from the following file: