public static function getIp() { $co = new Curl(self::$ifconfigIp); $co->setopt(CURLOPT_RETURNTRANSFER, true); $ip = $co->exec(); return $ip; }
function test_mock() { Curl::initMock(); Curl::mockResult("helloworld"); $curl = new Curl(); $res = $curl->exec(); $this->assertEquals($res, "helloworld"); }
function __construct($username, $password) { $curl = new Curl($this->loginUrl); $curl->setRefer($this->refer); $formData = array("shop_user" => array("login" => $username, "pass" => $password, "mem" => "on"), "auth" => "войти на сайт"); $curl->setReturnTransfer(true); $curl->sendPostForm($formData); $curl->exec(); echo curl_getinfo($curl, CURLINFO_HEADER_OUT); $curl->close(); }
function testCurlWrapperCanDoHttpQueries() { $curl = new Curl(self::TEST_VALID_URL); $curl->setopt(CURLOPT_PROXY, $this->proxy); $this->assertTrue($curl->setopt(CURLOPT_RETURNTRANSFER, 1)); $this->assertTrue($curl->setopt_array(array(CURLOPT_TIMEOUT => self::CURL_TIMEOUT, CURLOPT_FOLLOWLOCATION => true))); $result = $curl->exec(); $this->assertStringStartsWith('<!doctype html>', $result); $curl->close(); $this->assertFalse($curl->hasHandle()); }
/** * url_exists function. * Checks to see if an url exists * * @access public * @param string $url * @return bool */ public static function url_exists($url) { $curl_options = array(CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_URL => $url); $curl = new Curl($curl_options); try { $curl->exec(); $error = FALSE; } catch (Exception $e) { $error = TRUE; } return $error; }
/** * * Return case's comments; I assume that there wouldn't be single requests for events of more than 1 case * (comments should be show when user clicks on proper button * Important: Function is not ready and not used yet. * that might be corrected/developed in future * * THIS NO WORK !!! * THIS NO WORK !!! * * @param int $caseID */ public function getComments($caseID) { $res = 'No comments for this case.'; $this->resetParams(); $this->setParam('cmd', 'search'); $this->setParam('token', $this->token); $this->setParam('q', $caseID); $this->setParam('cols', 'events'); $this->curl->setopt_array($this->getCurlOptions()); $xml = $this->curl->exec(); if (!empty($xml)) { $dom = new DOMDocument(); $dom->loadXML($xml); //$case = $dom->getElementsByTagName( 'case' ); $events = $dom->getElementsByTagName('event'); //->item(0)->nodeValue; unset($res); $res = array(); foreach ($events as $event) { $res[] = array('ixPerson' => $event->getElementsByTagName('ixPerson')->item(0)->nodeValue, 'sPerson' => $event->getElementsByTagName('sPerson')->item(0)->nodeValue, 'ixPersonAssignedTo' => $event->getElementsByTagName('ixPersonAssignedTo')->item(0)->nodeValue, 'dt' => $event->getElementsByTagName('dt')->item(0)->nodeValue, 'evtDescription' => $event->getElementsByTagName('evtDescription')->item(0)->nodeValue, 'sChanges' => $event->getElementsByTagName('sChanges')->item(0)->nodeValue); } } return $res; }
<?php include '../lib/Curl.php'; include '../lib/Curl/Share.php'; /** * curl_share_init() example * * http://php.net/manual/en/function.curl-share-init.php#refsect1-function.curl-share-init-examples */ // Create cURL share handle and set it to share cookie data $sh = new Curl\Share(); $sh->setopt(CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE); // Initialize the first cURL handle and assign the share handle to it $ch1 = new Curl("http://example.com/"); $ch1->setopt(CURLOPT_SHARE, $sh); // Execute the first cURL handle $ch1->exec(); // Initialize the second cURL handle and assign the share handle to it $ch2 = new Curl("http://php.net/"); $ch2->setopt(CURLOPT_SHARE, $sh); // Execute the second cURL handle // all cookies from $ch1 handle are shared with $ch2 handle $ch2->exec(); // Close the cURL share handle $sh->close(); // Close the cURL handles $ch1->close(); $ch2->close();
<?php require_once __DIR__ . "/../../src/utils/Curl.php"; $curl = new Curl("http://learning.tunapanda.org/wp-content/plugins/wp-remote-sync/tests/lab/recvfile.php"); $curl->setopt(CURLOPT_RETURNTRANSFER, TRUE); $curl->setopt(CURLOPT_POST, 1); $curl->addFileUpload("thefile.txt", __DIR__ . "/file.txt"); $res = $curl->exec(); echo $res;
// If something happened, (which it shouldn't) throw an exception if (!$curl) { throw new Exception("I couldn't create a Curl object. Was PHP compiled with cURL?"); } /** * Set the URL for $curl to our test location: */ $curl->url = "http://jamessocol.com/projects/oocurl_test.php"; /** * Set a custom header for the test. */ $curl->httpheader = array('X-OOCurl-Version: ' . Curl::VERSION); /** * Execute the HTTP query */ $response = $curl->exec(); // If there's no response, there was an error. if (!$response) { throw new Exception("I couldn't fetch the response."); } printf("Single request: Success: %s\n", $response); printf("I downloaded %n bytes!\n", $curl->info('size_download')); // Now we'll test the parallel processor /** * Let's fetch Yahoo */ $y = new Curl("http://www.yahoo.com/"); /** * And let's grab Google, too */ $g = new Curl("http://www.google.com/");
<?php require_once __DIR__ . "/../../src/utils/Curl.php"; /*$curl=new Curl(); $curl ->setopt(CURLOPT_URL,"http://localhost/repo/wp-remote-sync/tests/lab/recvfile.php?getarg=1&json=1") ->setopt(CURLOPT_RETURNTRANSFER,TRUE) ->setResultDecoding(Curl::JSON); $res=$curl->exec(); print_r($res);*/ /* $curl=new Curl("http://localhost/wp-sync-test-remote/wp-content/plugins/wp-remote-sync/api.php"); $curl // ->setopt(CURLOPT_RETURNTRANSFER,TRUE) ->addPostField("action","getAttachment") ->addPostField("type","attachment") ->setResultDecoding(Curl::JSON) ->addPostField("slug","3d") ->addPostField("key","") ->addPostField("attachment","2016/01/3D2.png") ->setDownloadFileName("hello.png"); $res=$curl->exec();*/ function onPercent($percent) { echo "percent: " . $percent . "\n"; } $curl = new Curl("http://localhost/repo/wp-remote-sync/tests/lab/generatelongcontent.php"); $curl->setPercentFunc("onPercent"); $curl->setopt(CURLOPT_RETURNTRANSFER, TRUE); $curl->exec();
<?php session_start(); //print_r( $_SERVER ); //exit; include "classes/curl.class.php"; $url_root = "http://kebot.me/dic/"; $oauth_url = $url_root . "OAuth.php"; $api_url = $url_root . "api.php"; if (isset($_SESSION[uid])) { echo $_SESSION[uid]; } //function begin(){ $curl = new Curl($oauth_url . "?app=begin"); $return = $curl->exec(); $para = json_decode($return, TRUE); //print_r( $para ); $_SESSION["oauth_token_secret"] = $para["oauth_token_secret"]; $_SESSION["oauth_token"] = $para["oauth_token"]; echo $para[url] . "http://" . $_SERVER[HTTP_HOST] . $_SERVER[PHP_SELF]; //} //begin(); switch ($_GET[app]) { case "login": break; }
<?php include '../lib/Curl.php'; /** * curl_init() example * * http://php.net/manual/en/function.curl-init.php#refsect1-function.curl-init-examples */ // create a new cURL resource $ch = new Curl(); // set URL and other appropriate options $ch->setopt(CURLOPT_URL, "http://www.example.com/"); $ch->setopt(CURLOPT_HEADER, 0); // grab URL and pass it to the browser $ch->exec(); // close cURL resource, and free up system resources $ch->close();