当前位置: 首页>>代码示例>>PHP>>正文


PHP Curl::setUserAgent方法代码示例

本文整理汇总了PHP中Curl\Curl::setUserAgent方法的典型用法代码示例。如果您正苦于以下问题:PHP Curl::setUserAgent方法的具体用法?PHP Curl::setUserAgent怎么用?PHP Curl::setUserAgent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Curl\Curl的用法示例。


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

示例1: __construct

 /**
  * Api constructor.
  *
  * @param string $apiKey API Key
  * @param string $environment API environment
  */
 public function __construct($apiKey, $environment)
 {
     ArgValidator::assert($apiKey, ['string', 'notEmpty']);
     ArgValidator::assert($environment, ['string', 'notEmpty']);
     $this->curl = new Curl();
     $this->curl->setOpt(CURLOPT_RETURNTRANSFER, true);
     $this->curl->setUserAgent('Mozilla/5.0 (X11; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0');
     $this->apiUrl = $this->getApiUrl($environment);
     $this->apiKey = $apiKey;
 }
开发者ID:gennadyx,项目名称:shop-logistics.ru-api,代码行数:16,代码来源:Api.php

示例2: __construct

 public function __construct($login, $hash, $subdomain, ICookieContainer $cookieContainer)
 {
     $this->_login = $login;
     $this->_hash = $hash;
     $this->_subdomain = $subdomain;
     $this->cookieContainer = $cookieContainer;
     $this->_curl = new Curl();
     $this->_curl->setUserAgent('amoCRM-API-client/1.0');
     $this->_curl->setHeader('Content-Type', 'application/json');
     $this->_curl->setOpt(CURLOPT_HEADER, false);
     $this->_curl->setOpt(CURLOPT_SSL_VERIFYPEER, 0);
     $this->_curl->setOpt(CURLOPT_SSL_VERIFYHOST, 0);
     $this->auth();
 }
开发者ID:nanodesu88,项目名称:amocrm,代码行数:14,代码来源:AmoCrm.php

示例3: applyCurlOptions

 /**
  * Apply cURL options
  */
 private function applyCurlOptions()
 {
     $this->curl->reset();
     $this->curl->setUserAgent('Shopello-PHP API Client/1.0');
     $this->curl->setHeader('X-API-KEY', $this->apiKey);
     $this->curl->setOpt(CURLOPT_ENCODING, 'gzip');
     $this->curl->setOpt(CURLOPT_HEADER, false);
     $this->curl->setOpt(CURLOPT_NOBODY, false);
     $this->curl->setOpt(CURLOPT_CONNECTTIMEOUT, 3);
     $this->curl->setOpt(CURLOPT_TIMEOUT, 300);
     foreach ($this->curlOptions as $key => $value) {
         $this->curl->setOpt($key, $value);
     }
 }
开发者ID:raket,项目名称:Shopello-PHP,代码行数:17,代码来源:ApiClient.php

示例4: _processTask

 protected function _processTask()
 {
     try {
         $curl = new Curl();
         $curl->setUserAgent('got/Tarth');
         if ($this->includeTarthHeader) {
             $curl->setHeader(\Tarth\Tool\Task::HEADER_ALLERIA_CRC, \Tarth\Tool\Task::getTarthHeader($this));
         }
         if (isset($this->header)) {
             foreach ($this->header as $key => $value) {
                 $curl->setHeader($key, $value);
             }
         }
         call_user_func_array(array($curl, strtolower($this->method)), array($this->url, $this->data));
         if ($curl->error) {
             return false;
         } else {
             //响应码大于300为请求失败
             return $curl->httpStatusCode < 300;
             //接口返回为json格式,返回值中有code为0
             //return $curl->response->code == 0;
         }
     } catch (Exception $e) {
     }
 }
开发者ID:pythias,项目名称:Tarth,代码行数:25,代码来源:ApiTask.php

示例5: create

 /**
  * Create user cache.
  *
  * @param string $user Twitter screen name
  * @return bool If successful true
  * @throws CacheException Any errors
  */
 public function create($user)
 {
     try {
         $path = config("cache.path") . "/{$user}";
         $json_file = "{$path}/data.json";
         if (!$this->exists($user)) {
             mkdir($path);
         }
         if (!file_exists($json_file)) {
             touch($json_file);
         }
         $response = $this->twistOAuth->get("users/show", ["id" => $user]);
         $image_url = str_replace("_normal", "", $response->profile_image_url_https);
         $info = new SplFileInfo($image_url);
         $curl = new Curl();
         $curl->setUserAgent(SaveTweet::APP_NAME . "/" . SaveTweet::APP_VERSION . " with PHP/" . PHP_VERSION);
         $curl->download($image_url, "{$path}/icon.{$info->getExtension()}");
         $curl->close();
         $data = ["name" => $response->name, "screen_name" => $response->screen_name, "id" => $response->id_str, "icon" => config("cache.http_path") . "/{$response->id_str}/icon.{$info->getExtension()}", "org_icon" => $image_url, "update_at" => time()];
         $json = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
         (new SplFileObject($json_file, "w"))->fwrite($json);
         return true;
     } catch (RuntimeException $e) {
         $this->_catch($e);
     }
 }
开发者ID:Hiroto-K,项目名称:SaveTweet,代码行数:33,代码来源:Cache.php

示例6: __construct

 /**
  * Create a new News Spider.
  *
  * @param  \Curl\Curl $curl
  * 
  * @return void
  */
 public function __construct(Curl $curl = null)
 {
     if (is_null($curl)) {
         $curl = new Curl();
         $curl->setUserAgent(self::USER_AGENT);
     }
     $this->curl = $curl;
 }
开发者ID:vanry,项目名称:news-spider,代码行数:15,代码来源:Spider.php

示例7: connect

 private function connect()
 {
     $curl = new Curl();
     $curl->setBasicAuthentication($this->adminUsername, $this->adminPassword);
     $curl->setUserAgent('');
     $curl->setReferrer('');
     $curl->setHeader('X-Requested-With', 'XMLHttpRequest');
     $this->curl = $curl;
 }
开发者ID:dbugit,项目名称:owncloud-php-interface,代码行数:9,代码来源:owncloudPHPInterface.php

示例8: __construct

 /**
  * 可传入自定义设置后的Curl\Curl实例
  *
  * @param  Curl\Curl  $curl
  * @return void
  */
 public function __construct(Curl $curl = null)
 {
     if (is_null($curl)) {
         $curl = new Curl();
         $curl->setUserAgent(self::USER_AGENT);
         //抓取跳转后的页面
         $curl->setOpt(CURLOPT_FOLLOWLOCATION, true);
     }
     $this->client = $curl;
 }
开发者ID:vanry,项目名称:baike-spider,代码行数:16,代码来源:Downloader.php

示例9: get_image_data

 protected function get_image_data($image_url)
 {
     $curl = new Curl();
     $curl->setOpt(CURLOPT_FOLLOWLOCATION, true);
     // typically you will want to follow redirects
     if ($this->user_agent) {
         $curl->setUserAgent($this->user_agent);
         // the default WordPress user agent may be rejected by certain servers
     }
     $response = $curl->get($image_url);
     return $response;
 }
开发者ID:bermanco,项目名称:wordpress-image-download,代码行数:12,代码来源:WordpressImageDownload.php

示例10: parse

 public function parse()
 {
     $curl = new Curl();
     foreach ($this->origins as $origin) {
         foreach ($this->queries as $query) {
             shuffle($this->userAgents);
             $curl->reset();
             $curl->setUserAgent($this->userAgents[0]);
             $curl->setOpt(CURLOPT_RETURNTRANSFER, true);
             $curl->get($origin, [self::QUERY_GET_PARAM => $query]);
             var_dump($curl->response);
         }
     }
 }
开发者ID:mohamedgpaly,项目名称:avtprsr,代码行数:14,代码来源:Avito.php

示例11: Curl

<?php

/**
 * Created by PhpStorm.
 * User: lee
 * Date: 15-12-25
 * Time: 下午2:01
 */
header('Content-Type:image/png');
require __DIR__ . "/../vendor/autoload.php";
use Curl\Curl;
$curl = new Curl();
$url = 'http://new.yangyue.com.cn/renhao_gv1_sjz/yzm.php';
$names = $_COOKIE[session_name()];
$host = $_SERVER['HTTP_HOST'];
if (is_dir($host)) {
} else {
    $res = mkdir(iconv("UTF-8", "GBK", $host), 0777, true);
}
$cookie_jar = dirname(__FILE__) . "/" . $host . '/' . $names;
$curl->setCookieJar($cookie_jar);
$curl->setUserAgent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/47.0.2526.73 Chrome/47.0.2526.73 Safari/537.36");
$g = $curl->get($url);
echo $g;
开发者ID:fifths,项目名称:good_voice_quick_vote,代码行数:24,代码来源:pic.php

示例12: configCurl

 /**
  * Configure Curl.
  *
  * @param Curl $curl
  * @param string $serverApiKey
  */
 protected static function configCurl(&$curl, $serverApiKey)
 {
     $curl->setUserAgent('PhpGcmQueue 2');
     $curl->setOpt(CURLOPT_SSL_VERIFYPEER, 1);
     $curl->setOpt(CURLOPT_SSL_VERIFYHOST, 2);
     $curl->setHeader('Authorization', 'key=' . $serverApiKey);
     $curl->setHeader('Content-Type', 'application/json');
 }
开发者ID:stevetauber,项目名称:php-gcm-queue,代码行数:14,代码来源:Sender.php

示例13: tempnam

<?php

require '../../vendor/autoload.php';
use Curl\Curl;
$cookiefile = tempnam("/tmp", "cookies");
$user_agent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1';
$curl = new Curl();
$curl->setUserAgent($user_agent);
$curl->setOpt(CURLOPT_HEADER, 0);
$curl->setopt(CURLOPT_RETURNTRANSFER, TRUE);
$curl->setopt(CURLOPT_FOLLOWLOCATION, TRUE);
$curl->setopt(CURLOPT_SSL_VERIFYPEER, FALSE);
$curl->setopt(CURLOPT_SSL_VERIFYHOST, FALSE);
$curl->setopt(CURLOPT_COOKIEFILE, $cookiefile);
$curl->setopt(CURLOPT_COOKIEJAR, $cookiefile);
$get = $curl->get('google.com');
var_dump($curl);
开发者ID:oz4n,项目名称:elastic-api,代码行数:17,代码来源:TestCurl.php

示例14: queryJson

 private function queryJson($url, $data = [])
 {
     echo "Querying {$url} ...\n";
     $curl = new Curl();
     $curl->setUserAgent(sprintf('%s/%s (+%s)', 'stat.ink', Yii::$app->version, 'https://github.com/fetus-hina/stat.ink'));
     $curl->get($url, $data);
     if ($curl->error) {
         throw new \Exception("Request failed: url={$url}, code={$curl->errorCode}, msg={$curl->errorMessage}");
     }
     return Json::decode($curl->rawResponse, false);
 }
开发者ID:frozenpandaman,项目名称:stat.ink,代码行数:11,代码来源:SplapiController.php

示例15: Curl

<?php

/**
 * Created by PhpStorm.
 * User: lee
 * Date: 15-12-18
 * Time: 下午4:51
 */
require __DIR__ . "/../vendor/autoload.php";
use Curl\Curl;
$curl = new Curl();
$curl->setUserAgent('');
$curl->setHeader('X-Requested-With', 'XMLHttpRequest');
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
$curl->get('http://www.example.com/');
if ($curl->error) {
    echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
} else {
    echo $curl->response;
}
var_dump($curl->requestHeaders);
var_dump($curl->responseHeaders);
开发者ID:fifths,项目名称:php_curl,代码行数:22,代码来源:example.php


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