Overview

Namespaces

  • Cron
  • None

Classes

  • _HtmlGrid_TableOut
  • _TransactionModel_RawSaveOperation
  • AccessControlComponent
  • AccessControlHelper
  • ActionListHelper
  • ActiveDirectoryUtils
  • AddCurrentPidToSchedulingShellCallLogs
  • AnonymousFunctionOperation
  • ArrayUtil
  • AssociationIntegrityBehavior
  • AtomicOperation
  • AuthenticationComponent
  • AuthenticationController
  • AuthenticationUser
  • AutocompleteDatasourceComponent
  • BaseModelComponent
  • Basics
  • CakeLayersHelper
  • CheckAndRunShell
  • ClassSearcher
  • CommandLineUtil
  • CommonValidationBehavior
  • ConfigurableShellCallsSchedulingTask
  • ConfigurationKey
  • ConfigurationKeys
  • ConfigurationKeysController
  • Context
  • ContextComponent
  • ContextHelper
  • Contexts
  • ControllerInspector
  • ControllerMenuHelper
  • CreateJournalingTables
  • CreateTableConfigurationKeys
  • CreateTableSchedulingConfigurableShellCalls
  • CreateTableSchedulingShellCallLogs
  • CreateTableSettedConfigurationKeys
  • CreateTableUserResetPasswordRequests
  • CreateTableUsers
  • CronSchedulingInstaller
  • CronValidationBehavior
  • CssBox
  • CssController
  • CssProperties
  • CssShell
  • CsvUtil
  • CustomDataModel
  • DatasourceDumperManager
  • DateTimeInput
  • DependencyShell
  • DetailHelper
  • DumperShell
  • ExtendedFieldsAccessControl
  • ExtendedFieldSet
  • ExtendedFieldSetHelper
  • ExtendedFieldsParser
  • ExtendedFormHelper
  • ExtendedHasManyAppModel
  • ExtendedOperationsBehavior
  • FieldDefinition
  • FieldRowDefinition
  • FieldSetDefinition
  • FieldSetLayoutHelper
  • FileOperations
  • FileOperations_Rename
  • FileOperations_SymLink
  • FileOperations_Touch
  • FileOperations_Unlink
  • FileSystem
  • FixConfigurationKeysPrimaryKey
  • FixSettedConfigurationKeysPrimaryKey
  • HasManyUtilsBehavior
  • HtmlDocument
  • HtmlGrid
  • HtmlGrid_Cell
  • HttpClient
  • HttpResponse
  • ImapClient
  • ImapMailBox
  • ImapParserShell
  • IncludePath
  • InputMasked
  • InputSearchable
  • InputsOnSubmit
  • InstallShell
  • JenkinsBuildShell
  • Journal
  • JournalDetail
  • JournalizedBehavior
  • JsonResponseComponent
  • LayoutsHelper
  • Ldap
  • LdapUtils
  • ListFieldSet
  • ListFieldSetHelper
  • ListsHelper
  • MailParser
  • Make
  • MenuHelper
  • MigrationAllPluginsShell
  • ModelOperations
  • ModelOperations_Delete
  • ModelOperations_Save
  • ModelTraverser
  • MysqlDumper
  • OpenLdapUtils
  • PaginatorUtilComponent
  • PaginatorUtilComponentFilter
  • PaginatorUtilHelper
  • Plugin
  • PluginManager
  • Reflections
  • RenameEnabledToActiveFromUsersTable
  • RunShellCallShell
  • ScaffoldUtilComponent
  • ScaffoldUtilHelper
  • Scheduling
  • SchedulingConfigurableShellCall
  • SchedulingConfigurableShellCallsController
  • SchedulingShellCallLog
  • SchedulingShellCallLogsController
  • SettedConfigurationKey
  • StuffreposPluginsRename
  • TimeZoneBehavior
  • TransactionModel
  • TransactionOperation
  • Translator
  • TranslatorShell
  • User
  • UserAuthenticationComponent
  • UserChangePassword
  • UserResetPassword
  • UserResetPasswordRequest
  • UserResetPasswordRequestSubmission
  • UsersController
  • ViewUtilHelper

Interfaces

  • AccessControlFilter
  • CommitableOperation
  • DatasourceDumper
  • MakeListener
  • SchedulingInstaller
  • TasksObject
  • UndoableOperation

Exceptions

  • LdapObjectNotWritableException
  • ModelTraverserException
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: App::uses('HttpResponse', 'Web.Lib');
  4: 
  5: class HttpClient {
  6: 
  7:     /**
  8:      *
  9:      * @var string
 10:      */
 11:     private $agent = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:11.0) Gecko/20100101 Firefox/11.0';
 12:     
 13:     /**
 14:      *
 15:      * @var string
 16:      */
 17:     private $referer = '';
 18:     
 19:     /**
 20:      *
 21:      * @var string
 22:      */
 23:     private $targetResponseDirectory = null;
 24:     
 25:     /**
 26:      *
 27:      * @var int
 28:      */
 29:     private static $targetCount = 0;
 30:     
 31:     /**
 32:      *
 33:      * @var boolean
 34:      */
 35:     private $followLocation = false;
 36: 
 37:     /**
 38:      *
 39:      * @param array $url
 40:      * @param array $parameters
 41:      * @return HttpResponse
 42:      */
 43:     public function doPost($url, $parameters = array()) {
 44:         return $this->_doRequest($url, $parameters, true);
 45:     }
 46: 
 47:     /**
 48:      *
 49:      * @param array $url
 50:      * @param array $parameters
 51:      * @return HttpResponse
 52:      */
 53:     public function doGet($url, $parameters = array()) {
 54:         return $this->_doRequest($url, $parameters, false);
 55:     }
 56:     
 57:     /**
 58:      *
 59:      * @param boolean $enabled 
 60:      */
 61:     public function setFollowLocation($enabled) {
 62:         $this->followLocation = $enabled;
 63:     }
 64:     
 65:     /**
 66:      * 
 67:      * @param string $path
 68:      */
 69:     public function setTargetResponseDirectory($path) {
 70:         $this->targetResponseDirectory = $path;
 71:     }
 72: 
 73:     /**
 74:      * 
 75:      * @param string $url
 76:      * @param array $parameters
 77:      * @param boolean $post
 78:      * @return \HttpResponse
 79:      */
 80:     private function _doRequest($url, $parameters, $post) {        
 81:         $curlOptions = array();        
 82:         
 83:         if ($post) {
 84:             $curlOptions[CURLOPT_URL] = $url;
 85:             $curlOptions[CURLOPT_POST] = true;
 86:             $curlOptions[CURLOPT_POSTFIELDS] = $this->_buildParameterLine($parameters);
 87:         } else {
 88:             $curlOptions[CURLOPT_URL] = $url . '?' . $this->_buildParameterLine($parameters);
 89:             $curlOptions[CURLOPT_POST] = false;
 90:         }
 91: 
 92:         $curlOptions[CURLOPT_USERAGENT] = $this->agent;
 93:         $curlOptions[CURLOPT_COOKIEJAR] = $this->_getCookiesFile();
 94:         $curlOptions[CURLOPT_COOKIEFILE] = $this->_getCookiesFile();
 95:         $curlOptions[CURLOPT_FOLLOWLOCATION] = $this->followLocation;
 96:         $curlOptions[CURLOPT_HEADER] = true;
 97:         $curlOptions[CURLOPT_RETURNTRANSFER] = true;
 98:         $curlOptions[CURLOPT_REFERER] = $this->referer;        
 99: 
100:         $this->referer = $url;
101:         $response = new HttpResponse($curlOptions);
102:         
103:         if ($this->targetResponseDirectory) {
104:             $path = $this->targetResponseDirectory.'/'.(++self::$targetCount).'.html';
105:             file_put_contents($path, $response->getBody());
106:         }
107:         
108:         return $response;
109:     }
110: 
111:     /**
112:      * 
113:      * @return string
114:      */
115:     private function _getCookiesFile() {
116:         if (empty($this->cookiesFile)) {
117:             $this->cookiesFile = tempnam("/tmp", "CURLCOOKIE");
118:         }
119:         return $this->cookiesFile;
120:     }
121: 
122:     /**
123:      * 
124:      * @param array $parameters
125:      * @return string
126:      */
127:     private function _buildParameterLine($parameters) {
128:         $pairs = array();
129:         foreach ($parameters as $key => $value) {
130:             $pairs[] = urlencode($key) . '=' . urlencode($value);
131:         }
132:         return implode('&', $pairs);
133:     }
134: 
135: }
136: 
137: ?>
API documentation generated by ApiGen 2.8.0