public function fromUrl($url) { $this->url = $url; // ブログによっては403ではじかれる。ユーザーエージェント?IP? $httpRequest = new HttpRequest($this->url); $httpRequest->exec(); $this->fromText($url, $httpRequest->getResponse()); }
function getUserMeta() { $url = "http://api.twitter.com/1/users/show.json?screen_name=" . $this->user; $r = new HttpRequest("get", $url); if ($r->getError()) { $this->error("Could not get user information"); } else { return json_decode($r->getResponse(), true); } }
function __construct($args) { $url = $this->formatUrl($args); echo "Getting {$url}\n"; $r = new HttpRequest("get", $url); if ($r->getError()) { echo $r->getError(); } else { $this->response = json_decode($r->getResponse(), true); } }
/** * @brief Return the canvas containing the QR code * * @return Canvas The canvas contianing the QR code */ public function getImage() { $irequest = new HttpRequest($this->getImageUrl()); if ($irequest) { $img = new StringImage($irequest->getResponse()); if ($img) { return $img; } throw new BaseException("Could not create canvas from response"); } throw new BaseException("Error requesting QR Code"); }
protected function request($url) { // Check if this is an url or a filename if (substr($url, 0, 4) != "http") { // File return json_decode(file_get_contents($url), true); } else { $r = new HttpRequest("get", $url); if ($r->getError()) { return false; } else { return json_decode($r->getResponse(), true); } } }
public function t_estXpathSetup() { return; $datPath = implode('/', [PATH_TEST, 'dat', 'ContentExtractor']); // $res = exec(sprintf('rm -rf %s/*', $datPath), $out); foreach ($this->getData() as $name => $testData) { $httpRequest = new HttpRequest($testData->url); $ret = $httpRequest->exec(); if (!$ret) { d($httpRequest->getError()); d($httpRequest->getInfo()); } $this->assertEquals(true, $ret); file_put_contents($datPath . '/' . $name, $httpRequest->getResponse()); } }
public function testGeneral() { $httpRequest = new HttpRequest('http://tuoitre.com.vn/conduongcuqua?q=example_query&page=2&t[]=4'); $this->assertEquals(['example_query'], $httpRequest->getList('q')); $this->assertEquals('example_query', $httpRequest->getParam('q')); $this->assertEquals('example_query', $httpRequest->getString('q')); $defaultValue = 'testvalue'; $this->assertEmpty($httpRequest->getGET()); $this->assertEmpty($httpRequest->getPOST()); $this->assertNotEmpty($httpRequest->getQuery()); $this->assertEmpty($httpRequest->getPOST()); $this->assertEquals('2', $httpRequest->getParam('page')); $this->assertEquals(2, $httpRequest->getInt('page')); $this->assertEquals(['4'], $httpRequest->getArray('t')); $this->assertEmpty([], $httpRequest->getArray('no_array')); $this->assertEquals([1], $httpRequest->getArray('no_array', [1])); $this->assertEquals($defaultValue, $httpRequest->getParam('no_query', $defaultValue)); $this->assertEquals($defaultValue, $httpRequest->getString('no_query', $defaultValue)); $this->assertEquals($defaultValue, $httpRequest->getParam('no_query', $defaultValue)); $this->assertTrue($httpRequest->isMethod('get')); $httpRequest->getResponse(); $this->assertEmpty($httpRequest->getFragment()); $httpRequest->setMethod('post'); $this->assertTrue($httpRequest->isPost()); $exception = new \RuntimeException('issue'); $httpRequest->setException($exception); $this->assertEquals($exception, $httpRequest->getException()); $httpRequest->example_params = 12; $this->assertEquals($httpRequest->example_params, 12); $httpRequest->setPath('/'); $this->assertEquals($httpRequest->getPath(), '/'); $httpRequest->setDispatched(false); $this->assertFalse($httpRequest->isDispatched()); $httpRequest->setControllerName('\\Platform\\Core\\Controller\\HomeController'); $httpRequest->setActionName('index'); $this->assertEquals($httpRequest->getControllerName(), '\\Platform\\Core\\Controller\\HomeController'); $this->assertEquals($httpRequest->getActionName(), 'index'); $httpRequest->dispatch(); $httpRequest->setParams(['more' => '2']); $this->assertNotEmpty($httpRequest->getParams()); $this->assertEquals('2', $httpRequest->getParam('more')); $httpRequest->getFullControllerName(); }
if (empty($query)) { die("No query given\n"); } echo "Downloading tweets with query '{$query}'\n"; $page = 1; $baseUrl = "http://search.twitter.com/search.json?q={$query}&rpp=100"; $tweets = array(); do { $url = $baseUrl . "&page={$page}"; echo "REQUEST: {$url} \n"; $r = new HttpRequest("GET", $url); if ($r->getError()) { echo "HTTP ERROR: " . $r->getError(); break; } else { $json = json_decode($r->getResponse(), true); // No more tweets? $length = count($json['results']); if ($length < 1) { echo "NO MORE TWEETS\n"; break; } $tweets = array_merge($tweets, $json['results']); print_r($tweets); file_put_contents("{$query}.json", json_encode($tweets)); $page++; } } while (true); // Convert to CSV as well $csvdata = array_map(function ($tweet) { return array("id" => $tweet['id'], "from_user" => $tweet['from_user'], "created_at" => $tweet['created_at'], "text" => $tweet['text']);
<?php $start = $_GET['start']; $token = $_GET['tok']; require_once 'query.php'; $q = new Query(); $sql = "select distinct USERID from session where ACCESS_TOKEN={$token}"; $val = $q->getallentires($sql); //var_dump($val); //$v=$val['USERID']; foreach ($val as $value) { # code... $v = $value['USERID']; //echo $v; } error_reporting(E_ALL); ini_set("display_errors", "1"); require_once 'Http2.php'; $r = new HttpRequest("post", "http://52.76.14.6:8080/BaatnaServer/rest/wish/get?start={$start}&count=15&type=1&another_user=6", array("access_token" => $token)); if ($r->getError()) { echo "sorry, an error occured"; } else { // parse json //var_dump($r->getResponse()); $js = json_decode($r->getResponse()); $obj = $js->{"response"}; $obj2 = $obj->wishes; echo json_encode($obj2); }
<?php $token = $_GET['tok']; error_reporting(E_ALL); ini_set("display_errors", "1"); require_once 'Http2.php'; $r = new HttpRequest("post", "http://52.76.14.6:8080/BaatnaServer/rest/auth/logout", array("access_token" => $token)); if ($r->getError()) { echo "sorry, an error occured"; } else { echo $r->getResponse(); } ?> ?>
/** * Sends a request to Reddit and returns the response received * * @access public * @param string $verb 'GET', 'POST', ... * @param string $url 'http://www.reddit.com/comments/6nw57.json' * @param string $body * @return array */ public function sendRequest($verb, $url, $body = '') { $request = new HttpRequest(); $request->setUrl($url); $request->setHttpMethod($verb); if ($verb === 'POST' && is_array($body)) { foreach ($body as $name => $value) { $request->setPostVariable($name, $value); } } if ($this->sessionCookie !== null) { $request->setCookie('reddit_session', $this->sessionCookie); } $response = $request->getResponse(); if (!$response instanceof HttpResponse) { return null; } // $this->dumpRateInfo($response->getHeaders()); $responseBody = $response->getBody(); $response = json_decode($responseBody, true); if (isset($response['data']['modhash'])) { $this->modHash = $response['data']['modhash']; } elseif (isset($response[0]['data']['modhash'])) { $this->modHash = $response[0]['data']['modhash']; } return $response; }
public static function updateFeatureCodes($lang, callback $callback = null) { $db = new DatabaseConnection(); $cache = base::expand('app:/cache/geonames/'); cb($callback, 'Downloading featurecodes', 0, 1); $url = self::getUrl('featureCodes_' . strtolower($lang) . '.txt'); $req = new HttpRequest($url); $lstr = strtolower($lang); $reqs = explode("\n", $req->getResponse()); $rows = 0; $ltime = 0; foreach ($reqs as $reql) { $rd = explode("\t", trim($reql) . "\t"); if (count($rd) > 3) { $db->updateRow("REPLACE INTO geonames_featurecodes " . "(featurecode,lang,featurename,description) VALUES (%s,%s,%s,%s)", $rd[0], $lstr, $rd[1], $rd[2]); if (microtime(true) > $ltime + 1) { cb($callback, 'Importing featurecodes ... ' . $rows . " records imported", 1); $ltime = microtime(true); } $rows++; } } cb($callback, "Imported featurecodes (" . $rows . " rows)"); }
<?php require 'class-http-request.php'; $r = new HttpRequest("get", "http://twitter.com/statuses/public_timeline.json"); if ($r->getError()) { echo "sorry, an error occured"; } else { // parse json and show tweets $tweets = json_decode($r->getResponse()); var_dump($tweets); }