function __construct($url) { if (!function_exists('curl_exec')) { die('Vtiger_HTTP_Client: Curl extension not enabled!'); } parent::__construct(); $this->_serviceurl = $url; $useragent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"; $this->set_user_agent($useragent); // Escape SSL certificate hostname verification curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 0); }
/** * Submits the given form. * * If $submitButtonName is given, that name is also submitted as a POST/GET value * This is available since some forms act differently based on which submit button * you press * @param RemoteForm $form The form to submit * @param String $submitButtonName The submit button to click * @return Browser Returns this browser object for chaining */ public function submitForm(RemoteForm $form, $submitButtonName = '') { // Find the button, and set the given attribute if we're pressing a button if (!empty($submitButtonName)) { $button = $this->_navigator->query("//input[@type='submit'][@name='" . str_replace("'", "\\'", $submitButtonName) . "']"); if ($button->length === 1) { $form->setAttributeByName($submitButtonName, $button->item(0)->getAttribute('value')); } } // Handle get/post switch (strtolower($form->getMethod())) { case 'get': /** * If we're dealing with GET, we build the query based on the * parameters that RemoteForm finds, and then navigate to * that URL */ $questionAt = strpos($form->getAction(), '?'); if ($questionAt === false) { $questionAt = strlen($form->getAction()); } $url = substr($form->getAction(), 0, $questionAt); $url = $this->_resolveUrl($url); $url .= '?' . http_build_query($form->getParameters()); $this->navigate($url); break; case 'post': /** * If we're posting, we simply build a query string, and * pass that as the post data to the Curl HTTP client's * post handler method. Then we handle the response. */ $this->_handleResponse($this->_curl->send_post_data($this->_resolveUrl($form->getAction()), $form->getParameters()), $form->getAction()); break; } // Chain return $this; }
/** * Send a request SPARQL of type insert data or delete data to endpoint directly. * If you want check the query before to send, it's better to use the function query() * in the class FourStore_StorePlus. * Example insert : PREFIX ex: <http://example.com/> INSERT DATA { GRAPH ex:mygraph { ex:a ex:p 12 .}} * Example delete : PREFIX ex: <http://example.com/> DELETE DATA { GRAPH ex:mygraph { ex:a ex:p 12 .}} * @param string $query : Query Sparql of type insert data or delete data only * @return boolean true if it did * @access public */ public function queryUpdate($query) { $post_endpoint = array_shift(explode("/sparql/", $this->_endpoint)) . "/update/"; $sUri = $post_endpoint; $data = array("update" => $query); $this->debugLog($query, $sUri); $client = new Curl_HTTP_Client(); $response = $client->send_post_data($sUri, $data); $code = $client->get_http_response_code(); $this->debugLog($query, $sUri, $code, $response); //FIXME in 4Store : check in the next version || $code == 0 || $code == 100 if ($code == 200) { return true; } else { $this->errorLog($query, $sUri, $code, $response); return false; } }
function curl($url, $referrer = 0, $post = 0, $cookies = 0, $auth = 0, $headersOnly = 0, $debug = 0) { $curl = new Curl_HTTP_Client(); if ($debug) { $curl->debug = 0; } //$url = 'http://web-sniffer.net/?url='.urlencode($url).'&rawhtml=yes&submit=Submit&http=1.1&gzip=yes&type=GET&uak=1'; //print '<br><br>URL:'.$url.'<br>'; //pretend to be IE6 on windows $useragent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"; $curl->set_user_agent($useragent); //uncomment next two lines if you want to manage cookies if ($cookies != 0) { $cookies_file = "cookies/cookies.txt"; $curl->store_cookies($cookies_file); } //Uncomment next line if you want to set credentials if ($auth != 0) { $username = $auth[0]; $password = $auth[1]; $curl->set_credentials($username, $password); } if ($headersOnly) { $curl->include_response_headers_only(); } //Uncomment next line if you want to set specific referrer if ($referrer != 0) { $curl->set_referrer($referrer); $referrerStr = 'Referer: ' . $str; } else { //$referrer='Referer: '; $referrerStr = ''; } $host = explode('/', $url); $host = $host[2]; //Set Headers $headers = array('GET / HTTP/1.1', 'Host: ' . $host, 'Connection: close', 'User-Agent: ' . $useragent, 'Accept-Encoding: gzip', 'Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7', 'Cache-Control: no', 'Accept-Language: de,en;q=0.7,en-us;q=0.3', $referrerStr); $curl->set_headers($headers); //if you want to send some post data //form post data array like this one if ($post != 0) { $post_data = $post; // $post = array('login' => 'pera', 'password' => 'joe', 'other_foo_field' => 'foo_value'); //and send request to http://www.foo.com/login.php. Result page is stored in $html_data string $html_data = $curl->send_post_data($url, $post_data); } else { $html_data = $curl->fetch_url($url); } //You can also fetch data from somewhere using get method! //Fetch html from url //$html_data = $curl->fetch_url("http://www.foo.com/foobar.php?login=pera&password=joe&other_foo_field=foo_value"); //if you have more than one IP on your server, //you can also bind to specific IP address like ... //$bind_ip = "192.168.0.1"; //$curl->fetch_url("http://www.foo.com/login.php", $bind_ip); //$html_data = $curl->send_post_data("http://www.foo.com/login.php", $post_data, $bind_ip); $curl->close(); if ($curl->debug || $_REQUEST['debug'] == 1) { print '<textarea>' . $html_data . '</textarea>'; //exit; } return $html_data; }