/** * 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; }
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(); }
/** * 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); } }
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) { } }
/** * 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); } }
/** * 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; }
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; }
/** * 可传入自定义设置后的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; }
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; }
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); } } }
<?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;
/** * 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'); }
<?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);
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); }
<?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);
/** * 向环信请求 * @param $url * @param string $params * @param string $type POST|GET * @return mixed * @throws \ErrorException */ private function contact($url, $params = '', $type = 'POST') { $postData = ''; if (is_array($params)) { $postData = json_encode($params); } $curl = new Curl(); $curl->setUserAgent('Jasonwx/Easemob SDK; Jason Wang<*****@*****.**>'); $curl->setOpt(CURLOPT_SSL_VERIFYPEER, false); $curl->setOpt(CURLOPT_SSL_VERIFYHOST, false); $curl->setHeader('Content-Type', 'application/json'); $token = ""; if ($url !== $this->url . '/token') { $token = $this->getToken(); $curl->setHeader('Authorization', 'Bearer ' . $token); } switch ($type) { case 'POST': $curl->post($url, $postData); break; case 'GET': $curl->get($url); break; case 'DELETE': $curl->delete($url); break; } $curl->close(); if ($this->debug) { echo "URL: {$url}\n Header: {$token} \nBody: \"{$postData}\"\n"; } if ($curl->error) { throw new \ErrorException('CURL Error: ' . $curl->error_message, $curl->error_code); } if ($this->debug) { // echo "return: {$curl->raw_response} \n"; } return json_decode($curl->raw_response, true); }
<?php /** * beiwo2podcast * https://github.com/Jamesits/beiwo2podcast * @author James Swineson * 2015-07-19 */ require_once 'config.php'; require_once 'Curl/Curl.php'; use Curl\Curl; header('charset=utf-8'); $id = $_GET['id']; $curl = new Curl(); $curl->setUserAgent($ua); $curl->setOpt(CURLOPT_ENCODING, 'gzip'); $curl->get('http://www.beiwo.ac/users/myPageDataWithPaging', array('id' => $userid, 'limit' => $limit, 'curItems' => 0)); if ($curl->error) { die('错误 ' . $curl->error_code . ':' . $curl->error_message); } $songdata0 = json_decode($curl->response, true); $userid = $songdata0['items'][0]['user']['objectId']; echo '{"soundId": "' . $id . '", "userId": "' . $userid . '"}';