本文整理汇总了PHP中Httpful\Request::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::get方法的具体用法?PHP Request::get怎么用?PHP Request::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Httpful\Request
的用法示例。
在下文中一共展示了Request::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: consultaTransacao
public function consultaTransacao($dadosCriptografados)
{
$xml = Request::get(static::URL_CONSULTA_TRANSACOES . $dadosCriptografados)->withoutStrictSsl()->expectsXml()->send();
if (!$xml) {
throw new \Exception("Nenhum dado coletado no webservice");
}
if ($xml->code != 200) {
throw new \Exception("O servidor retornou status {$xml->code}");
}
return $this->populateConsultaTransacao($xml->body);
}
示例2: testCitiesListContainsAmsterdam
public function testCitiesListContainsAmsterdam()
{
$uri = "http://localhost:8000";
$response = Request::get($uri)->send();
$this->assertEquals("application/json", $response->headers["Content-Type"]);
$this->assertContains("Amsterdam", $response->body);
}
示例3: getRates
public function getRates(Currency $base)
{
$rates = (array) Request::get(sprintf('http://api.fixer.io/latest?base=%s', $base->getName()))->send()->body->rates;
$ret = [];
foreach ($rates as $key => $rate) {
$ret[$key] = $rate;
}
return $ret;
}
示例4: getPhotos
function getPhotos($category, $posts)
{
$is_highlights = !is_array($posts);
$data = !$is_highlights ? $posts : [];
$url = 'http://' . $_SERVER['SERVER_NAME'] . '/' . 'cms/wp-json/posts?filter[posts_per_page]=-1&filter[order]=desc&filter[orderby]=post_date' . ($is_highlights ? '&filter[category_name]=destaque' : null);
$response = \Httpful\Request::get($url)->send();
$catId = get_cat_ID($category);
foreach ($response->body as $key => $post) {
$image_src = getImage($post->content);
$attachment_id = pn_get_attachment_id_from_url($image_src);
$image_large_src = wp_get_attachment_image_src($attachment_id, 'large');
if (!$is_highlights && !isHighgligthCategory($catId, $post->terms->category)) {
if ($image_src) {
array_push($data, array('id' => $post->ID, 'title' => $post->title, 'image_src' => getImage($post->content), 'image_large_src' => $image_large_src[0]));
}
} else {
if ($is_highlights && isHighgligthCategory($catId, $post->terms->category)) {
if ($image_src) {
array_push($data, array('id' => $post->ID, 'title' => $post->title, 'image_src' => getImage($post->content), 'image_large_src' => $image_large_src[0]));
}
}
}
}
return $data;
}
示例5: httpGet
protected function httpGet($uri)
{
$results = [];
// Start requesting at page 1
$page = 1;
// We dont know how many pages there are, so assume 1 until we know
$pagecount = 1;
while ($page <= $pagecount) {
$this->log[] = ['request' => ['method' => 'GET', 'uri' => $uri . '?page=' . $page]];
$response = \Httpful\Request::get($uri . '?page=' . $page)->addHeader('X-Auth-Email', $this->email)->addHeader('X-Auth-Key', $this->apikey)->expectsType(\Httpful\Mime::JSON)->parseWith(function ($body) {
return \Metaclassing\Utility::decodeJson($body);
})->send()->body;
$this->log[count($this->log) - 1]['response'] = $response;
if ($response['success'] != true) {
throw new \Exception("get {$uri} unsuccessful" . \Metaclassing\Utility::encodeJson($response));
}
foreach ($response['result'] as $result) {
array_push($results, $result);
}
// Now that we KNOW the pagecount, update that and increment our page counter
$pagecount = $response['result_info']['total_pages'];
// And get the next page ready for the next request
$page++;
}
return $results;
}
示例6: getResponse
private function getResponse($url)
{
$response = \Httpful\Request::get($url)->send();
$responseraw = $response->raw_body;
$result = json_decode($responseraw, true);
return $result;
}
示例7: sendRequest
private function sendRequest($url, $data, array $options = null, $auth = null, $apiKey = null)
{
array_merge($this->_headers, $options);
if ($this->_method == GET) {
$url = $url . http_build_query($data);
$this->_result = Request::get($url)->send();
} else {
if ($this->_method == POST) {
if (isset($apiKey)) {
$url .= array_keys($apiKey)[0] . "=" . array_values($apiKey)[0];
}
$request = Request::post($url);
foreach ($this->_headers as $key => $hdr) {
$request = $request->addHeader($key, $hdr);
}
if ($this->headers["Content-Type"] = "application/x-www-form-urlencoded" and is_array($data)) {
$request = $request->body(http_build_query($data));
} else {
$request = $request->body($data);
}
if (isset($auth)) {
$request = $request->authenticateWith(array_keys($auth)[0], array_values($auth)[0]);
}
$this->_result = $request->send();
}
}
}
示例8: getNewsObjects
function getNewsObjects()
{
//CACHING ENABLED: The server will only fetch news again if the cache has expired. Set expiry values in caching.php
/*************** CACHE **************/
$newsCacheName = 'newscache';
$responsejson = null;
$cacheExpired = is_null(checkCache($newsCacheName));
$noCache = !is_null($_GET["nocache"]);
////////////////////////
if ($cacheExpired || $noCache) {
$uri = "http://api.nytimes.com/svc/news/v3/content/all/all.json?api-key={$newsapikey}";
$rawresponsejson = \Httpful\Request::get($uri)->send();
$responsejson = $rawresponsejson . raw_body;
setCacheVal($newsCacheName, $responsejson);
if ($debug) {
echo "Fetched.";
}
} else {
if ($debug) {
echo "From cache.";
}
$responsejson = getCacheVal($newsCacheName);
}
return parseArticleObjectsFromJson($responsejson);
}
示例9: get
/**
* {@inheritdoc}
*/
public function get($url)
{
$response = Request::get($url)->sendsJson()->addHeader("Accept", "application/json")->addHeader('X-TOKEN', $this->api)->send();
if ($this->isResponseOk($response->code)) {
return $response->body;
}
}
示例10: fetch
private function fetch(&$str, $productid, $page, $count)
{
echo 'page is ' . $page . PHP_EOL;
// echo 'current str length is '.strlen($str).PHP_EOL;
$has_more = true;
$url = sprintf($this->url_format, $productid, $page, $count);
$headers = ['Cookie' => '_customId=q77dbffe7014; _snmc=1; _snsr=direct%7Cdirect%7C%7C%7C; _snma=1%7oC143589353017297011%7C1435893530172%7C1435893530172%7C1435893530171%7C1%7C1; _snmp=143589353016073744; _snmb=143589353017914712%7C1435893530308%7C1435893530180%7C1; _ga=GA1.2.833540218.1435893530; _snmz=143589353016073744%7C%281049%2C3268%29'];
try {
$response_ = Request::get($url)->addHeaders($headers)->autoParse(false)->send();
} catch (\Exception $e) {
return false;
}
//生成一个csv文件格式
$json_str = substr($response_->raw_body, 11, -1);
$arr = json_decode($json_str, true);
// echo 'json_str is '.$json_str.PHP_EOL;
// echo 'current json_str length is '.strlen($json_str).PHP_EOL;
if (strlen($json_str) > 0 && !is_null($arr) && isset($arr['commodityReviews'])) {
//echo "commodity reviews arr count is ".count($arr['commodityReviews']).PHP_EOL;
foreach ($arr['commodityReviews'] as $comment) {
$content = $comment['content'];
str_replace('\'', '', $content);
str_replace('"', '', $content);
str_replace(',', '', $content);
$str .= $content . "\r\n";
}
} else {
$has_more = false;
}
return $has_more;
}
示例11: authenticate
public function authenticate($ticket, $service)
{
$r = Request::get($this->getValidateUrl($ticket, $service))->sendsXml()->timeoutIn($this->timeout)->send();
$r->body = str_replace("\n", "", $r->body);
try {
$xml = new SimpleXMLElement($r->body);
} catch (\Exception $e) {
throw new \UnexpectedValueException("Return cannot be parsed : '{$r->body}'");
}
$namespaces = $xml->getNamespaces();
$serviceResponse = $xml->children($namespaces['cas']);
$user = $serviceResponse->authenticationSuccess->user;
if ($user) {
return (string) $user;
// cast simplexmlelement to string
} else {
$authFailed = $serviceResponse->authenticationFailure;
if ($authFailed) {
$attributes = $authFailed->attributes();
throw new \Exception((string) $attributes['code']);
} else {
throw new \Exception($r->body . " service:" . $service);
}
}
// never reach there
}
示例12: fetchOriginal
public function fetchOriginal($showTitle, $season, $episode)
{
$episodeLink = $this->fetchEpisodeLink($showTitle, $season, $episode);
$doc = Request::get($episodeLink)->send()->body;
$dom = new DOMDocument('1.0', 'utf-8');
@$dom->loadHTML($doc);
$xp = new DOMXPath($dom);
$links = $xp->query('//strong[text()="original"]');
if ($links->length == 0) {
$links = $xp->query('//table[@class="tabel95"]//td[@class="language"][contains(text(),"English")]');
if ($links->length == 0) {
echo "Subtitle not found: {$episodeLink}\n";
return;
} else {
$tds = $links;
$links = [];
foreach ($tds as $td) {
$linkNode = $xp->query('../td/a[@class="buttonDownload"]/strong', $td)->item(0);
if ($linkNode) {
$links[] = $linkNode;
}
}
}
}
foreach ($links as $linkNode) {
$link = $linkNode->parentNode->getAttribute('href');
$subLink = "http://www.addic7ed.com{$link}";
$response = Request::get($subLink)->addHeader('Referer', $episodeLink)->send();
$disp = $response->headers['Content-Disposition'];
preg_match('/filename="([^"]+)"/', $disp, $m);
return ['filename' => $m[1], 'body' => $response->body];
}
}
示例13: getHttpServer
/**
* @param Request $request
*
* @return HttpServer
*/
public function getHttpServer(Request $request)
{
$url = $request->getUri();
switch ($request->getMethod()) {
case Request::METHOD_POST:
$httpServer = HttpServer::post($url);
break;
case Request::METHOD_PUT:
$httpServer = HttpServer::put($url);
break;
case Request::METHOD_DELETE:
$httpServer = HttpServer::delete($url);
break;
default:
$httpServer = HttpServer::get($url);
break;
}
if ($request->headers) {
$httpServer->addHeaders($request->headers->all());
}
if ($request->getUser()) {
$httpServer->authenticateWith($request->getUser(), $request->getPassword());
}
if ($request->getContent()) {
$httpServer->body($request->getContent());
}
return $httpServer;
}
示例14: send
/**
* Send the HipChat message.
*
* @return void
*/
public function send()
{
$message = $this->message ?: ucwords($this->getSystemUser()) . ' ran the [' . $this->task . '] task.';
$format = $message != strip_tags($message) ? 'html' : 'text';
$payload = ['auth_token' => $this->token, 'room_id' => $this->room, 'from' => $this->from, 'message' => $message, 'message_format' => $format, 'notify' => 1, 'color' => $this->color];
Request::get('https://api.hipchat.com/v1/rooms/message?' . http_build_query($payload))->send();
}
示例15: resetDatabase
/**
* Reset passbolt installation
* @return bool
*/
public static function resetDatabase($url, $dummy = 'seleniumtests')
{
$response = \Httpful\Request::get($url . '/seleniumTests/resetInstance/' . $dummy)->send();
$seeCreated = preg_match('/created/', $response->body);
sleep(2);
// Wait for database to be imported (no visible output).
return $seeCreated;
}