ultimix
http.php
Go to the documentation of this file.
1 <?php
2 
3  /*
4  * This source code is a part of the Ultimix Project.
5  * It is distributed under BSD license. All other third side source code (like tinyMCE) is distributed under
6  * it's own license wich could be found from the corresponding files or sources.
7  * This source code is provided "as is" without any warranties or garanties.
8  *
9  * Have a nice day!
10  *
11  * @url http://ultimix.sorceforge.net
12  *
13  * @author Alexey "gdever" Dodonov
14  */
15 
26  class http_1_0_0
27  {
46  function set( $FieldName , $FieldValue )
47  {
48  $this->$FieldName = $FieldValue;
49  }
50 
61  var $host = 'localhost';
62 
73  var $url = '/';
74 
85  var $type = 'POST';
86 
109  private function default_init( $Data )
110  {
111  try
112  {
113  $Curl = curl_init();
114 
115  curl_setopt( $Curl , CURLOPT_FAILONERROR , 1 );
116  curl_setopt( $Curl , CURLOPT_RETURNTRANSFER , 1 );
117  curl_setopt( $Curl , CURLOPT_TIMEOUT , 20 );
118  curl_setopt( $Curl , CURLOPT_POST , $this->type == 'POST' );
119  curl_setopt( $Curl , CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)" );
120  curl_setopt( $Curl , CURLOPT_URL , "$this->host$this->url" );
121 
122  if( $Data != '' )
123  {
124  curl_setopt( $Curl , CURLOPT_POSTFIELDS , "$Data" );
125  }
126 
127  return( $Curl );
128  }
129  catch( Exception $e )
130  {
131  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
132  }
133  }
134 
157  function http_request( $Data = '' )
158  {
159  try
160  {
161  $Curl = $this->default_init( $Data );
162 
163  $RequestData = curl_exec( $Curl );
164 
165  if( curl_errno( $Curl ) )
166  {
167  throw( new Exception( curl_error( $Curl ) ) );
168  }
169 
170  curl_close( $Curl );
171 
172  return( $RequestData );
173  }
174  catch( Exception $e )
175  {
176  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
177  }
178  }
179 
202  function https_request( $Data = '' )
203  {
204  try
205  {
206  $Curl = $this->default_init( $Data );
207 
208  curl_setopt( $Curl , CURLOPT_SSLVERSION , 3 );
209  curl_setopt( $Curl , CURLOPT_SSL_VERIFYPEER , false );
210  curl_setopt( $Curl , CURLOPT_SSL_VERIFYHOST , 2 );
211 
212  $RequestData = curl_exec( $Curl );
213 
214  if( curl_errno( $Curl ) )
215  {
216  throw( new Exception( curl_error( $Curl ) ) );
217  }
218 
219  curl_close( $Curl );
220 
221  return( $RequestData );
222  }
223  catch( Exception $e )
224  {
225  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
226  }
227  }
228 
251  function fetch_request_header( $RequestData )
252  {
253  try
254  {
255  $RequestParts = explode( "\r\n\r\n" , $RequestData );
256 
257  return( $RequestParts[ 0 ] );
258  }
259  catch( Exception $e )
260  {
261  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
262  }
263  }
264 
287  function fetch_request_body( $RequestData )
288  {
289  try
290  {
291  $RequestParts = explode( "\r\n\r\n" , $RequestData );
292 
293  $Start = strpos( $RequestParts[ 1 ] , "\r\n" );
294 
295  return( substr( $RequestParts[ 1 ] , $Start + 2 ) );
296  }
297  catch( Exception $e )
298  {
299  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
300  }
301  }
302  }
303 
304 ?>