private function doRequest($method, $url, array $header, $data) { $curlInit = curl_init(); $parsed_url = parse_url($url); if (isset($parsed_url['scheme']) && $parsed_url['scheme'] !== 'http' && $parsed_url['scheme'] !== 'https') { return false; } if ($method === 'GET') { curl_setopt($curlInit, CURLOPT_POST, 0); } elseif ($method === 'POST') { curl_setopt($curlInit, CURLOPT_POST, 1); curl_setopt($curlInit, CURLOPT_POSTFIELDS, $data); } curl_setopt($curlInit, CURLOPT_URL, $url); curl_setopt($curlInit, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curlInit, CURLOPT_RETURNTRANSFER, true); curl_setopt($curlInit, CURLINFO_HEADER_OUT, true); curl_setopt($curlInit, CURLOPT_TIMEOUT, $this->timeout); if (!empty($header)) { curl_setopt($curlInit, CURLOPT_HTTPHEADER, $header); } if (!empty($this->proxy_host) && !in_array($parsed_url["host"], $this->proxy_exclude)) { curl_setopt($curlInit, CURLOPT_PROXY, $this->proxy_host); curl_setopt($curlInit, CURLOPT_PROXYPORT, $this->proxy_port); } $response = new stdClass(); $response->content = curl_exec($curlInit); $response->header = curl_getInfo($curlInit, CURLINFO_HEADER_OUT); $response->status = (int) curl_getInfo($curlInit, CURLINFO_HTTP_CODE); $response->contentType = curl_getInfo($curlInit, CURLINFO_CONTENT_TYPE); $response->error = curl_error($curlInit); curl_close($curlInit); return $response; }
public function call($url, $data = array()) { $hdl = curl_init($url); $postFields = json_encode($data); curl_setopt($hdl, CURLOPT_RETURNTRANSFER, true); curl_setopt($hdl, CURLOPT_HTTPHEADER, array('Accept: json')); curl_setopt($hdl, CURLOPT_TIMEOUT, 10); curl_setopt($hdl, CURLOPT_POST, true); curl_setopt($hdl, CURLOPT_POSTFIELDS, $postFields); curl_setopt($hdl, CURLINFO_CONTENT_TYPE, 'application_json'); curl_setopt($hdl, CURLOPT_SSL_VERIFYPEER, false); $body = curl_exec($hdl); $info = curl_getInfo($hdl); curl_close($hdl); $result = json_decode($body, true); if (!count($result)) { throw new NullPostResponseException(print_r($info, true) . $body); } return $result; }
protected function callService($url, $data = array()) { $data = array_merge(array('key' => $this->api_key, 'secret' => $this->api_secret), $data); $postFields = json_encode($data); $hdl = curl_init($url); curl_setopt($hdl, CURLOPT_RETURNTRANSFER, true); curl_setopt($hdl, CURLOPT_HTTPHEADER, array('Accept: json')); curl_setopt($hdl, CURLOPT_TIMEOUT, 10); curl_setopt($hdl, CURLOPT_POST, true); curl_setopt($hdl, CURLOPT_POSTFIELDS, $postFields); curl_setopt($hdl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($hdl, CURLINFO_CONTENT_TYPE, 'application_json'); curl_setopt($hdl, CURLOPT_SSL_VERIFYPEER, false); $body = curl_exec($hdl); $info = curl_getInfo($hdl); curl_close($hdl); $result = json_decode($body, true); if (!count($result)) { file_put_contents(dirname(__FILE__) . '/../../../../../../web/last-error.html', $body); var_dump($info); die; } return $result; }
public function get_remote_file($file_url) { $session = curl_init($file_url); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); curl_setopt($session, CURLOPT_FOLLOWLOCATION, 1); $exec = curl_exec($session); $info = curl_getInfo($session); if ($info['http_code'] == 200) { return $exec; } else { return false; } }
/** * @param int $option Option. * * @return mixed */ public function getInfo(int $option = NULL) { if (is_null($option)) { return curl_getInfo($this->getHandle()); } return curl_getInfo($this->getHandle(), $option); }
protected function fetch_file($url, $header = false) { if (!$header) { $header = "application/rss+xml"; } $headers[] = "Content-Type: {$header}; charset=UTF-8"; $headers[] = "Accept: {$header}; charset=UTF-8"; $session = curl_init($url); curl_setopt($session, CURLOPT_HTTPHEADER, $headers); curl_setopt($session, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); curl_setopt($session, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"); $exec = curl_exec($session); $info = curl_getInfo($session); if ($info['http_code'] == 200) { return $exec; } else { return false; } }
/** * action the curl request, return result or false * @return mixed */ private function curl_send() { $exec = curl_exec($this->db); $info = curl_getInfo($this->db); if ($info['http_code'] == 200) { if ($this->return_curl_data) { return $exec; } else { return true; } } else { return false; } }
public function createSocket() { if (function_exists(self::LZF_FUNCTION)) { $base = "create-socket/"; } else { $base = "create-socket-no-lzf/"; } $url = $this->base_url . $base . $this->project_id; $data = array('key' => $this->api_key, 'secret' => $this->api_secret); $postFields = json_encode($data); $hdl = curl_init($url); curl_setopt($hdl, CURLOPT_RETURNTRANSFER, true); curl_setopt($hdl, CURLOPT_HTTPHEADER, array('Accept: json')); curl_setopt($hdl, CURLOPT_TIMEOUT, 10); curl_setopt($hdl, CURLOPT_POST, true); curl_setopt($hdl, CURLOPT_POSTFIELDS, $postFields); curl_setopt($hdl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($hdl, CURLINFO_CONTENT_TYPE, 'application_json'); curl_setopt($hdl, CURLOPT_SSL_VERIFYPEER, false); $body = curl_exec($hdl); $info = curl_getInfo($hdl); curl_close($hdl); $result = json_decode($body, true); if (!count($result)) { file_put_contents(dirname(__FILE__) . '/../last-error.html', $body); var_dump($info); die; } return $result; }
public function sendRequest($payload = '') { $retVal = 'null'; if ($this->_lastToken == null) { //try to get authentication token $this->getAuthToken(); } if ($this->_lastToken != null) { $ch = curl_init(); curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . "/cacert.pem"); curl_setopt($ch, CURLOPT_URL, $this->_url . $payload); //curl_setopt($ch, CURLOPT_HTTPGET, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded;charset=UTF-8', 'Authorization:Bearer ' . $this->_lastToken)); $retVal = curl_exec($ch); $this->_lastInfo = curl_getInfo($ch); curl_close($ch); $st = $this->_lastInfo['http_code']; if ($st == 401 && $this->_numretries == 0) { //auto retry 1 time $this->_numretries++; return $this->sendRequest($payload); } } return $retVal; }