Not documented yet
This class is to provide HTTP access to the Web. This documentation doesn't describe the functions of the class, but rather how to use it. The code is taken from the geo_kit plugin.
The test code is this:
$url = "http://api.akelos.org"; $geocoder = new Geocoder; $result = $geocoder->call_geocoder_service($url);
The Geocoder::call_geocoder_service() function accepts a URL and produces an array with the result of the HTTP call. It can be found in a program that has installed the geo_kit at app/vendor/plugins/geo_kit/lib/geocoders.php.
include_once AK_FRAMEWORK_DIR.DS.'lib'.DS.'AkHttpClient.php'; function call_geocoder_service($url) { $response_msg = array( 100=>array('100 Continue','information'), # This array contains all of the message codes that HTTP might return, along with # the associated message and the message class. The full array is shown after the code. 507=>array('507 Insufficient Storage','server error')); $http = new AkHttpClient; $options = array(); # This code creates options to be submitted to the HTTP request. if($this->geocoders->timeout > 0) { $options['timeout'] = $this->geocoders->timeout; } if(!is_null($this->geocoders->proxy_addr)) { $options['_proxy_host'] = $this->geocoders->proxy_addr; $options['_proxy_port'] = $this->geocoders->proxy_port; if(!is_null($this->geocoders->proxy_user)) { $options['_proxy_user'] = $this->geocoders->proxy_user; if(!is_null($this->geocoders->proxy_pass)) { $options['_proxy_pass'] = $this->geocoders->proxy_pass; } } } $result = array(); # This is the HTTP call. $instance is needed because we want to get the http version. # Sample output is shown below as "HTTP Request Instance". $instance = $http->getRequestInstance($url, 'GET', $options); # This gets the page contents. Sample output, the web page, is shown below as "HTTP Request Body". $body = $http->get($url, $options); # This gets the result code, which is then evaluated in the array at the beginning of this function. $result['code'] = $http->getResponseCode(); if($response_msg[$result['code']][1] != 'success') { $result['body'] = $response_msg[$result['code']][0]; $result['success'] = false; }else{ # We could have assigned $http->getResponseHeaders() to a variable, then parsed the variable. If # we had done so, we'd have gotten an array similar to that shown in "HTTP Response Headers". # Instead, we chose to get just what we wanted with calls to getResponseHeader(). $result['content-type'] = $http->getResponseHeader('Content-Type'); $result['server'] = $http->getResponseHeader('Server'); $result['content-length'] = $http->getResponseHeader('Content-Length'); $result['body'] = $body; $result['http-version'] = $instance->_http; $result['success'] = true; } return $result; } // function call_geocoder_service
This associative array is indexed by response code. The first value in each resulting array is the message. The second value is the category of the code, so that you can examine a result code by category.
$response_msg = array( 100=>array('100 Continue','information'), 101=>array('101 Switching Protocols','information'), 102=>array('102 Processing','information'), 200=>array('200 OK','success'),array('201 Created','success'), 202=>array('202 Accepted','success'), 203=>array('203 Non-Authoriative Information','success'), 204=>array('204 No Content','success'), 205=>array('205 Reset Content','success'), 206=>array('206 Partial Content','success'), 207=>array('207 Multi-Status','success'), 300=>array('300 Multiple Choices','redirection'), 301=>array('301 Moved Permanently','redirection'), 302=>array('302 Found','redirection'), 303=>array('303 See Other','redirection'), 304=>array('304 Not Modified','redirection'), 305=>array('305 Use Proxy','redirection'), 306=>array('306 (Unused)','redirection'), 307=>array('307 Temporary Redirect','redirection'), 400=>array('400 Bad Request','client error'), 401=>array('401 Unauthorized','client error'), 402=>array('402 Payment Granted','client error'), 403=>array('403 Forbidden','client error'), 404=>array('404 Not found','client error'), 405=>array('405 Method Not Allowed','client error'), 406=>array('406 Not Acceptable','client error'), 407=>array('407 Proxy Authentication Required','client error'), 408=>array('408 Request Time-out','client error'), 409=>array('409 Conflict','client error'), 410=>array('410 Gone','client error'), 411=>array('411 Length Required','client error'), 412=>array('412 Precondition Failed','client error'), 413=>array('413 Request Entity Too Large','client error'), 414=>array('414 Request-URI Too Large','client error'), 415=>array('415 Unsupported Media Type','client error'), 416=>array('416 Requested range not satisfiable','client error'), 417=>array('417 Expectation Failed','client error'), 422=>array('422 Unprocessable Entity','client error'), 423=>array('423 Locked','client error'), 424=>array('424 Failed Dependency','client error'), 500=>array('500 Internal Server Error','server error'), 501=>array('501 Not Implemented','server error'), 502=>array('502 Bad Gateway','server error'), 503=>array('503 Service Unavailable','server error'), 504=>array('504 Gateway Timeout','server error'), 505=>array('505 HTTP Version Not Supported','server error'), 507=>array('507 Insufficient Storage','server error'));
This is the value of $instance in the code. We use it to extract the HTTP version: _http.
HTTP_Request Object ( [_url] => Net_URL Object( [options] => Array( [encode_query_keys] => ) [url] => http://api.akelos.org [protocol] => http [username] => [password] => [host] => api.akelos.org [port] => 80 [path] => / [querystring] => Array() [anchor] => [useBrackets] => 1 [user] => [pass] => ) [_method] => GET [_http] => 1.1 [_requestHeaders] => Array ( [host] => api.akelos.org [connection] => close [accept-encoding] => gzip [user-agent] => Akelos PHP Framework AkHttpClient (http://akelos.org) ) [_user] => [_pass] => [_sock] => [_proxy_host] => [_proxy_port] => [_proxy_user] => [_proxy_pass] => [_postData] => Array() [_body] => [_bodyDisallowed] => Array( [0] => TRACE ) [_postFiles] => Array() [_timeout] => [_response] => [_allowRedirects] => [_maxRedirects] => 3 [_redirects] => 0 [_useBrackets] => 1 [_listeners] => Array() [_saveBody] => 1 [_readTimeout] => [_socketOptions] => )
This is the body of the HTTP request
<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//FR" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <!-- Generated by phpDocumentor on Tue, 17 Jun 2008 14:22:19 +0200 --> <title>Akelos Framework API</title> <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/> </head> <FRAMESET cols='220,*'> <FRAMESET rows='220,*'> <FRAME src='packages.html' name='left_top'> <FRAME src='li_AkelosFramework.html' name='left_bottom'> </FRAMESET> <FRAME src='blank.html' name='right'> <NOFRAMES> <H2>Frame Alert</H2> <P>This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client.</P> </NOFRAMES> </FRAMESET>
Array
(
[date] => Wed, 17 Dec 2008 14:00:33 GMT
[server] => Apache/1.3.37 (Unix) mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 FrontPage/5.0.2.2635.SR1.2 mod_ssl/2.8.28 OpenSSL/0.9.7a
[last-modified] => Tue, 17 Jun 2008 12:22:19 GMT
[etag] => "3595ee-363-4857ac92"
[accept-ranges] => bytes
[content-length] => 867
[connection] => close
[content-type] => text/html
)
Not documented yet