/** * Makes an HTTP request of the specified $method to a $url with an optional array or string of $vars * * Returns a CurlResponse object if the request was successful, false otherwise * * @param string $method * @param string $url * @param array|string $vars * @return CurlResponse|boolean */ public function request($method, $url, $vars = array()) { $this->error = Null; $used_proxies = 0; if (is_array($vars)) { $this->vars = http_build_query($vars, '', '&'); } if (!is_string($url) and $url !== '') { throw new CurlException("Invalid URL: " . $url); } do { $this->closeRequest(); $this->request = curl_init(); if (count($this->proxies) > $used_proxies) { //$this->setOption['HTTPPROXYTUNNEL'] = True; $this->setOption('PROXY', $this->proxies[$used_proxies]['ip'] . ':' . $this->proxies[$used_proxies]['port']); $this->setOption('PROXYPORT', $this->proxies[$used_proxies]['port']); //$this->setOption('PROXYTYPE', CURLPROXY_HTTP); $this->setOption('TIMEOUT', $this->proxies[$used_proxies]['timeout']); if ($this->proxies[$used_proxies]['user'] !== NUll and $this->proxies[$used_proxies]['pass'] !== Null) { $this->setOption('PROXYUSERPWD', $this->proxies[$used_proxies]['user'] . ':' . $this->proxies[$used_proxies]['pass']); } $used_proxies++; } else { unset($this->option['PROXY'], $this->option['PROXYPORT'], $this->option['PROXYTYPE'], $this->option['PROXYUSERPWD']); } //debug::dump($this->options); $this->set_request_method($method); $this->set_request_options($url); $this->set_request_headers(); $response = curl_exec($this->request); $this->error = curl_errno($this->request) . ' - ' . curl_error($this->request); $this->info = curl_getinfo($this->request); } while (curl_errno($this->request) == 6 and count($this->proxies) < $used_proxies); $this->closeRequest(); if ($response) { $response = new CurlResponse($response, $this); $response_headers = $response->getHeaders(); if (isset($response_headers['Location']) and $this->getFollowRedirects()) { $response = $this->request($this->getMethod(), $response_headers['Location']); } } else { if ($this->info['http_code'] == 400) { throw new CurlException('Bad request - ' . $response); } elseif ($this->info['http_code'] == 401) { throw new CurlException('Permission Denied - ' . $response); } else { throw new CurlException($this->error); } } return $response; }