• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP HttpClient类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中HttpClient的典型用法代码示例。如果您正苦于以下问题:PHP HttpClient类的具体用法?PHP HttpClient怎么用?PHP HttpClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了HttpClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: getSearcherValue

 function getSearcherValue($url, $searcher = "google")
 {
     $url = urlencode(preg_replace("#^http://#", "", $url));
     $searcherUrls = array('google' => 'http://www.google.com/search?hl=en&q=site%3A' . $url, 'googlebl' => 'http://www.google.com/search?hl=en&q=link%3A' . $url);
     $searcherPats = array('google' => "#</b> of (?:about )?<b>([\\d,]+)</b>#", 'googlebl' => "#</b> of (?:about )?<b>([\\d,]+)</b>#");
     if (!array_key_exists($searcher, $searcherUrls)) {
         $searcher = "google";
     }
     $sourceUrl = $searcherUrls[$searcher];
     $httpClient = new HttpClient();
     if ($this->extractionWay == 2) {
         $httpClient->additionalServerUrl = $this->additionalServerUrl;
     }
     $buff = $httpClient->getSiteContent($sourceUrl);
     if ($this->debug) {
         echo $buff;
     }
     if (!preg_match($searcherPats[$searcher], $buff, $m)) {
         $count = 0;
     } else {
         $count = str_replace(",", "", $m[1]);
         $count = intval($count);
     }
     return $count;
 }
开发者ID:reinfire,项目名称:arfooo,代码行数:25,代码来源:GoogleStats.php


示例2: uploadContents

 public function uploadContents($content)
 {
     if ($this->data['appkey'] === null) {
         throw new \InvalidArgumentException('appkey should not be null!');
     }
     if ($this->data['timestamp'] === null) {
         throw new \InvalidArgumentException('timestamp should not be null!');
     }
     if (!is_string($content)) {
         throw new \InvalidArgumentException('content should be a string!');
     }
     $post = array('appkey' => $this->data['appkey'], 'timestamp' => $this->data['timestamp'], 'content' => $content);
     $url = $this->host . $this->uploadPath;
     $postBody = json_encode($post);
     $sign = md5('POST' . $url . $postBody . $this->appMasterSecret);
     $url = $url . '?sign=' . $sign;
     $http = new HttpClient();
     $http->execute($url, $postBody);
     if ($http->httpCode === '0') {
         //time out
         throw new \UnexpectedValueException('Curl error number:' . $http->curlErrNo . ' , Curl error details:' . $http->curlErr . '\\r\\n');
     } elseif ($http->httpCode !== '200') {
         //we did send the notifition out and got a non-200 response
         throw new \UnexpectedValueException('http code:' . $http->httpCode . PHP_EOL . ' details:' . $http->result . '\\r\\n');
     }
     $returnData = json_decode($http->result, true);
     if ($returnData['ret'] === 'FAIL') {
         throw new \UnexpectedValueException('Failed to upload file, details:' . $http->result . '\\r\\n');
     } else {
         $this->data['file_id'] = $returnData['data']['file_id'];
     }
 }
开发者ID:netroby,项目名称:umeng-php-sdk,代码行数:32,代码来源:AndroidFilecast.php


示例3: handleWebhook

 /**
  * Handles the actual webhook, happens in two steps:
  *
  * - Retrieves the $webhook_id and $event_id
  *
  * - Uses the key and secret provided to fetch the event object and casts it to an array
  *
  * - Calls the callable function with the Event object
  */
 private function handleWebhook()
 {
     $identifier = $this->field('identifier');
     if ($identifier !== $this->identifier) {
         return;
     }
     $event_id = $this->field('event_id');
     $webhook_id = $this->field('webhook_id');
     if (!$event_id || !$webhook_id) {
         Log::info($this->patrol, 'Webhook ' . $this->identifier . ' has no event_id or webhook_id');
         return;
     }
     $httpClient = new HttpClient($this->patrol, 'GET', 'webhooks/' . $webhook_id . '/events/' . $event_id);
     $response = $httpClient->response();
     if (!$response) {
         Log::info($this->patrol, 'Retrieving webhook from ' . $httpClient->getUrl() . ' failed');
         return;
     }
     $data = $this->field($response, 'data');
     if (!$data) {
         Log::info($this->patrol, 'Event has invalid format to be processed: ' . print_r($response, true));
     }
     $callable = $this->callback;
     if (is_callable($callable)) {
         $callable($data);
     }
 }
开发者ID:zdevil,项目名称:patrolsdk-php,代码行数:36,代码来源:Webhook.php


示例4: getMetaDataAction

 function getMetaDataAction()
 {
     $httpClient = new HttpClient();
     $metaData = $httpClient->getMetaValues($this->request->url);
     $this->set($metaData);
     $this->viewClass = "JsonView";
 }
开发者ID:reinfire,项目名称:arfooo,代码行数:7,代码来源:SiteController.php


示例5: __construct

 public function __construct(HttpUrl $claimedId, HttpClient $httpClient)
 {
     $this->claimedId = $claimedId->makeComparable();
     if (!$claimedId->isValid()) {
         throw new OpenIdException('invalid claimed id');
     }
     $this->httpClient = $httpClient;
     $response = $httpClient->send(HttpRequest::create()->setHeaderVar('Accept', self::HEADER_ACCEPT)->setMethod(HttpMethod::get())->setUrl($claimedId));
     if ($response->getStatus()->getId() != 200) {
         throw new OpenIdException('can\'t fetch document');
     }
     $contentType = $response->getHeader('content-type');
     if (mb_stripos($contentType, self::HEADER_CONT_TYPE) !== false) {
         $this->parseXRDS($response->getBody());
     } elseif ($response->hasHeader(self::HEADER_XRDS_LOCATION)) {
         $this->loadXRDS($response->getHeader(self::HEADER_XRDS_LOCATION));
     } else {
         $this->parseHTML($response->getBody());
     }
     if (!$this->server || !$this->server->isValid()) {
         throw new OpenIdException('bad server');
     } else {
         $this->server->makeComparable();
     }
     if (!$this->realId) {
         $this->realId = $claimedId;
     } elseif (!$this->realId->isValid()) {
         throw new OpenIdException('bad delegate');
     } else {
         $this->realId->makeComparable();
     }
 }
开发者ID:onphp-framework,项目名称:onphp-framework,代码行数:32,代码来源:OpenIdCredentials.class.php


示例6: reverse

 static function reverse($latitude, $longitude)
 {
     if (!$latitude || !$longitude) {
         throw new \Exception('no coords set');
     }
     $temp = TempStore::getInstance();
     $key = 'GeonamesClient//' . $latitude . '/' . $longitude;
     $data = $temp->get($key);
     if ($data) {
         return unserialize($data);
     }
     $url = 'http://ws.geonames.org/timezone?lat=' . $latitude . '&lng=' . $longitude;
     $http = new HttpClient($url);
     $data = $http->getBody();
     $xml = simplexml_load_string($data);
     //d($xml);
     $res = new GeoLookupResult();
     $res->country_code = strval($xml->timezone->countryCode);
     $res->country_name = strval($xml->timezone->countryName);
     $res->timezone = strval($xml->timezone->timezoneId);
     $res->sunrise = strval($xml->timezone->sunrise);
     $res->sunset = strval($xml->timezone->sunset);
     $temp->set($key, serialize($res), '1h');
     return $res;
 }
开发者ID:martinlindhe,项目名称:core_dev,代码行数:25,代码来源:GeonamesClient.php


示例7: verify

 /**
  * Verifies a recaptcha
  *
  * @param $priv_key private recaptcha key
  * @return true on success
  */
 public function verify()
 {
     $error = ErrorHandler::getInstance();
     $conf = RecaptchaConfig::getInstance();
     if (empty($_POST['recaptcha_challenge_field']) || empty($_POST['recaptcha_response_field'])) {
         $error->add('No captcha answer given.');
         return false;
     }
     if (!$conf->getPublicKey() || !$conf->getPrivateKey()) {
         die('ERROR - Get Recaptcha API key at http://recaptcha.net/api/getkey');
     }
     $params = array('privatekey' => $conf->getPrivateKey(), 'remoteip' => client_ip(), 'challenge' => $_POST['recaptcha_challenge_field'], 'response' => $_POST['recaptcha_response_field']);
     $http = new HttpClient($this->api_url_verify);
     $res = $http->post($params);
     $answers = explode("\n", $res);
     if (trim($answers[0]) == 'true') {
         return true;
     }
     switch ($answers[1]) {
         case 'incorrect-captcha-sol':
             $e = 'Incorrect captcha solution';
             break;
         default:
             $e = 'untranslated error: ' . $answers[1];
     }
     $error->add($e);
     return false;
 }
开发者ID:martinlindhe,项目名称:core_dev,代码行数:34,代码来源:Recaptcha.php


示例8: core_call

 public function core_call($serialized_request)
 {
     $client = new HttpClient($this->domain);
     $client->setCookies($this->cookies);
     $client->post($this->location . "json/", $serialized_request);
     return $client->getContent();
 }
开发者ID:JamesHyunKim,项目名称:weblabdeusto,代码行数:7,代码来源:WebLabHttpRequestGateway.class.php


示例9: parse

 function parse($raw)
 {
     // TODO XmlReader should not handle HTTP protocol details
     if (is_url($raw)) {
         $url = $raw;
         $h = new HttpClient($url);
         //            $h->setCacheTime('30m');
         $raw = $h->getBody();
         //            d( $h->getResponseHeaders() );
         if ($h->getStatus() == 404) {
             // not found
             return false;
         }
         if ($h->getStatus() == 302) {
             $redir = $h->getResponseHeader('location');
             // echo "REDIRECT: ".$redir."\n";
             $h = new HttpClient($redir);
             //XXX: reuse previous client?
             $h->setCacheTime('30m');
             $url = $redir;
             $raw = $h->getBody();
         }
         // prepend XML header if nonexistent
         if (strpos($raw, '<?xml ') === false) {
             $raw = '<?xml version="1.0"?>' . $raw;
         }
     }
     if (!$this->xml($raw)) {
         if (isset($url)) {
             throw new \Exception("Failed to parse XML from " . $url);
         }
         throw new \Exception("Failed to parse XML");
     }
 }
开发者ID:martinlindhe,项目名称:core_dev,代码行数:34,代码来源:XmlReader.php


示例10: beacon_send_message

function beacon_send_message($channel, $data)
{
    $url = '/1.0.0/' . get_option('beacon_api_key') . '/channels/' . $channel;
    $client = new HttpClient('api.beaconpush.com');
    $client->extra_request_headers = array('X-Beacon-Secret-Key: ' . get_option('beacon_secret_key'));
    $client->post($url, json_encode($data));
}
开发者ID:heyman,项目名称:beacon-wordpress,代码行数:7,代码来源:beacon-wordpress.php


示例11: http_get_file

function http_get_file($url)
{
    $httpClient = new HttpClient("epub.cnki.net");
    $httpClient->get($url);
    $content = $httpClient->getContent();
    return $content;
}
开发者ID:highestgoodlikewater,项目名称:cnkispider,代码行数:7,代码来源:index.php


示例12: _remoteCall

 protected function _remoteCall($method, $params = null)
 {
     $uri = $this->reportServer;
     $cache_id = md5($this->objectName . $uri . $method . serialize($params));
     $cacheSvc = Openbiz::getService(CACHE_SERVICE, 1);
     $cacheSvc->init($this->objectName, $this->cacheLifeTime);
     if (substr($uri, strlen($uri) - 1, 1) != '/') {
         $uri .= '/';
     }
     $uri .= "ws.php/udc/CollectService";
     if ($cacheSvc->test($cache_id) && (int) $this->cacheLifeTime > 0) {
         $resultSetArray = $cacheSvc->load($cache_id);
     } else {
         try {
             $argsJson = urlencode(json_encode($params));
             $query = array("method={$method}", "format=json", "argsJson={$argsJson}");
             $httpClient = new HttpClient('POST');
             foreach ($query as $q) {
                 $httpClient->addQuery($q);
             }
             $headerList = array();
             $out = $httpClient->fetchContents($uri, $headerList);
             $cats = json_decode($out, true);
             $resultSetArray = $cats['data'];
             $cacheSvc->save($resultSetArray, $cache_id);
         } catch (Exception $e) {
             $resultSetArray = array();
         }
     }
     return $resultSetArray;
 }
开发者ID:openbizx,项目名称:openbizx-cubix,代码行数:31,代码来源:ErrorReportService.php


示例13: parse

 /** @return array of VcardAddress objects */
 static function parse($data)
 {
     if (is_url($data)) {
         $http = new HttpClient($data);
         $data = $http->getBody();
         //FIXME check http client return code for 404
         if (strpos($data, 'BEGIN:VCARD') === false) {
             throw new \Exception('VcardReader->parse FAIL: cant parse vcard from ' . $http->getUrl());
             return false;
         }
     }
     $res = array();
     do {
         $m1 = 'BEGIN:VCARD';
         $m2 = 'END:VCARD';
         $p1 = strpos($data, $m1);
         $p2 = strpos($data, $m2);
         if ($p1 === false || $p2 === false) {
             break;
         }
         $part = substr($data, $p1, $p2 - $p1 + strlen($m2));
         $res[] = self::parseVcard($part);
         $data = substr($data, $p2 + strlen($m2));
     } while ($data);
     return $res;
 }
开发者ID:martinlindhe,项目名称:core_dev,代码行数:27,代码来源:VcardReader.php


示例14: testEffectiveUrl

 /**
  * @dataProvider effectiveUrls
  */
 public function testEffectiveUrl($url, $expected, $params = array())
 {
     $http = new HttpClient();
     $http->get($url, $params);
     $this->assertEquals($expected, $http->getEffectiveUrl());
     $this->assertEquals($expected, $http->effectiveUrl);
 }
开发者ID:urmaul,项目名称:httpclient,代码行数:10,代码来源:InfoTest.php


示例15: switchAction

 public function switchAction($action, $httpVars, $filesVars)
 {
     if (!isset($this->actions[$action])) {
         return false;
     }
     $repository = ConfService::getRepository();
     if (!$repository->detectStreamWrapper(true)) {
         return false;
     }
     $streamData = $repository->streamData;
     $destStreamURL = $streamData["protocol"] . "://" . $repository->getId();
     if ($action == "post_to_server") {
         $file = base64_decode(AJXP_Utils::decodeSecureMagic($httpVars["file"]));
         $target = base64_decode($httpVars["parent_url"]) . "/plugins/editor.pixlr";
         $tmp = call_user_func(array($streamData["classname"], "getRealFSReference"), $destStreamURL . $file);
         $fData = array("tmp_name" => $tmp, "name" => urlencode(basename($file)), "type" => "image/jpg");
         $httpClient = new HttpClient("pixlr.com");
         //$httpClient->setDebug(true);
         $postData = array();
         $httpClient->setHandleRedirects(false);
         $params = array("referrer" => "AjaXplorer", "method" => "get", "loc" => ConfService::getLanguage(), "target" => $target . "/fake_save_pixlr.php", "exit" => $target . "/fake_close_pixlr.php", "title" => urlencode(basename($file)), "locktarget" => "false", "locktitle" => "true", "locktype" => "source");
         $httpClient->postFile("/editor/", $params, "image", $fData);
         $loc = $httpClient->getHeader("location");
         header("Location:{$loc}");
     } else {
         if ($action == "retrieve_pixlr_image") {
             $file = AJXP_Utils::decodeSecureMagic($httpVars["original_file"]);
             $url = $httpVars["new_url"];
             $urlParts = parse_url($url);
             $query = $urlParts["query"];
             $params = array();
             $parameters = parse_str($query, $params);
             $image = $params['image'];
             /*
             $type = $params['type'];
             $state = $params['state'];
             $filename = $params['title'];		
             */
             if (strpos($image, "pixlr.com") == 0) {
                 throw new AJXP_Exception("Invalid Referrer");
             }
             $headers = get_headers($image, 1);
             $content_type = explode("/", $headers['Content-Type']);
             if ($content_type[0] != "image") {
                 throw new AJXP_Exception("File Type");
             }
             $orig = fopen($image, "r");
             $target = fopen($destStreamURL . $file, "w");
             while (!feof($orig)) {
                 fwrite($target, fread($orig, 4096));
             }
             fclose($orig);
             fclose($target);
             header("Content-Type:text/plain");
             print $mess[115];
         }
     }
     return;
 }
开发者ID:firstcoder55,项目名称:Webkey,代码行数:59,代码来源:class.PixlrEditor.php


示例16: send

 /**
  * to config content data and send to target
  * @param array $data - content data in array
  *	(format like array(
  *		"first"=>array("value"=>"","color"=>""), 
  *		"remark"=>array("value"=>"","color"=>""))
  *	)
  * @return data received after posting
  */
 public function send($data)
 {
     $this->body['data'] = $data;
     $json = json_encode($this->body);
     $client = new HttpClient("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$this->access_token}");
     $client->setParameter($json);
     return $client->post();
 }
开发者ID:jianhua1982,项目名称:wlight,代码行数:17,代码来源:template.php


示例17: testJsonPost

 function testJsonPost()
 {
     $http = new HttpClient('http://localhost/coredev_testserver/post_json.php');
     $http->setContentType('application/json');
     $http->setDebug(true);
     $res = $http->post(array('str' => 'abc 123'));
     $this->assertEquals($res, 'str=abc+123');
 }
开发者ID:martinlindhe,项目名称:core_dev,代码行数:8,代码来源:HttpClientTest.php


示例18: getRate

 public static function getRate($from, $to)
 {
     $url = 'http://rate-exchange.appspot.com/currency?from=' . strtoupper($from) . '&to=' . strtoupper($to);
     $http = new HttpClient($url);
     $res = $http->getBody();
     $json = json_decode($res);
     return $json->rate;
 }
开发者ID:martinlindhe,项目名称:core_dev,代码行数:8,代码来源:CurrencyFetcherGoogle.php


示例19: message_put

 public function message_put($proxy_at, $from, $body, $srv_addr, $srv_at, $mod_params)
 {
     $channelId = 1;
     $priority = 100;
     $text = $body;
     $url = 'http://botq.localhost/api/textMessage/' . $channelId . '/' . $priority . '/' . urlencode($text);
     $hc = new \HttpClient();
     $hc->request($url);
 }
开发者ID:Cyrille37,项目名称:WebMessagesDispatcher,代码行数:9,代码来源:BotQ.php


示例20: send

 public function send($content)
 {
     $data = array("touser" => $this->openid, "msgtype" => "text", "text" => array("content" => urlencode($content)));
     $data = urldecode(json_encode($data));
     $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={$this->access_token}";
     $client = new HttpClient($url);
     $client->setParameter($data);
     return $client->post();
 }
开发者ID:jianhua1982,项目名称:wlight,代码行数:9,代码来源:custom.php



注:本文中的HttpClient类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP HttpException类代码示例发布时间:2022-05-23
下一篇:
PHP Http类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap