Verify SSL peer
public static verifyPeer ( boolean $enabled ) : boolean | ||
$enabled | boolean | enable SSL verification, by default is true |
Результат | boolean |
/** * Constructor */ public function __construct() { $this->output = new ConsoleOutput(); Request::verifyPeer(false); Request::verifyHost(false); Request::cookieFile('/tmp/cookie.dat'); }
public function sendContent($from, $to, $subject, $type, $content) { if (is_string($to)) { $to = [$to]; } $recipients = Mailjet::parse_recipient_type($to); // Build the HTTP POST body text if ($type == 'html') { $body = http_build_query(array('from' => $from, 'to' => implode(', ', $recipients['to']), 'cc' => implode(', ', $recipients['cc']), 'bcc' => implode(', ', $recipients['bcc']), 'subject' => $subject, 'html' => $content)); } else { if ($type == 'text') { $body = http_build_query(array('from' => $from, 'to' => implode(', ', $recipients['to']), 'cc' => implode(', ', $recipients['cc']), 'bcc' => implode(', ', $recipients['bcc']), 'subject' => $subject, 'text' => $content)); } else { throw new Exception('Wrong email type'); } } utils::log($body); $options = array('scheme' => 'http', 'host' => 'api.mailjet.com', 'path' => '/v3/send/'); $endpoint = Mailjet::unparse_url($options); $headers = array('Authorization' => 'Basic ' . $this->_authentificate, 'Content-Type' => 'application/x-www-form-urlencoded', 'Content-Length' => strlen($body)); // API request Unirest\Request::verifyPeer(false); $response = Unirest\Request::post($endpoint, $headers, $body); utils::log('STATUS: ' . $response->code); utils::log('HEADERS: ' . json_encode($response->headers)); utils::log('BODY: ' . $response->raw_body); return $response->code == 200; }
/** * Constructor. */ public function __construct() { Unirest::verifyPeer(false); //Unirest::httpVersion($this->httpVersion); $ref = new ReflectionClass($this); $this->gatewayName = strtolower($ref->getShortName()); }
/** * Run the database seeds. * * @return void */ public function run() { HTTPRequest::verifyPeer(env('UNIREST_VERIFYPEER')); //Get 10 quotes, from a Mashape API for ($i = 0; $i < 10; $i++) { $response = HTTPRequest::post("https://andruxnet-random-famous-quotes.p.mashape.com/cat=famous", array("X-Mashape-Key" => env('MASHAPE_KEY'), "Content-Type" => "application/x-www-form-urlencoded", "Accept" => "application/json")); Quote::create(["content" => $response->body->quote, "author" => $response->body->author, "source" => "https://andruxnet-random-famous-quotes.p.mashape.com/cat=famous"]); } }
public function make_request($options) { $injector = Injector::getInstance(); $url = $options['url']; $method = $options['method']; $headers = $options['headers']; $body = isset($options['body']) ? $options['body'] : ''; $response = null; if (isset($options['qs'])) { $qs = http_build_query($options['qs']); $url .= '?' . $qs; } $url = str_replace('%2C', ',', $url); if (isset($headers['Content-Type']) && $headers['Content-Type'] == 'application/json' && is_array($body)) { $body = json_encode($body); } Request::verifyPeer($injector->ssl_verification); $response = Request::send($options['method'], $url, $body, $headers); return $response; }
<?php /* * Include composer and configuration files */ require_once BASE_DIR . 'vendor/autoload.php'; \Unirest\Request::verifyPeer(false); \Unirest\Request::timeout(5); /* * Include required files */ require_once SRC_DIR . 'core/components/authentication.php'; require_once SRC_DIR . 'core/components/errorhandler.php'; require_once SRC_DIR . 'core/components/functions.php'; require_once SRC_DIR . 'core/components/daemon.php'; require_once SRC_DIR . 'core/components/page.php'; require_once SRC_DIR . 'core/components/url.php'; require_once SRC_DIR . 'core/config/configinterface.php'; require_once SRC_DIR . 'core/config/jsonconfig.php'; require_once SRC_DIR . 'core/config/databaseconfig.php'; require_once SRC_DIR . 'core/config/inmemdatabaseconfig.php'; require_once SRC_DIR . 'core/config.php'; require_once SRC_DIR . 'core/databasemanager.php'; require_once SRC_DIR . 'core/authentication.php'; require_once SRC_DIR . 'core/email.php'; require_once SRC_DIR . 'core/files.php'; require_once SRC_DIR . 'core/user.php'; require_once SRC_DIR . 'core/language.php'; require_once SRC_DIR . 'core/log.php'; require_once SRC_DIR . 'core/permissions.php'; require_once SRC_DIR . 'core/server.php';
/** * Actual request implementation. * @param $params * @return \Unirest\Response */ private function requestInternal($params) { \Unirest\Request::verifyPeer((bool) $this->sslVerifyPeer); /** @var $response \Unirest\Response */ $response = \Unirest\Request::get($this->apiEndpoint, ['user-agent' => $this->userAgent], $params); return $response; }
public function uri(Silex\Application $app, Request $request) { $bodyParams = json_decode($request->getContent()); $uri = $bodyParams->uri; $identifier = $bodyParams->identifier; $original_filename = $bodyParams->name ?: str_replace('/.*\\//', '', str_replace('/[\\?#].*$/', '', urldecode($uri))); Unirest\Request::verifyPeer(false); //$response =Unirest\Request::head ($uri, [], null) ; $http = new \ADN\Extract\HttpRequest($uri, [], null, null); $response = $http->head(); if (!$request || $response->code != Response::HTTP_OK) { return new Response('', $response->code, ['Content-Type' => 'text/plain']); } $length = utils::findKey($response->headers, 'Content-Length') ?: -1; $data = (object) array('key' => $identifier, 'name' => $original_filename, 'uri' => $uri, 'size' => $length, 'bytesRead' => 0, 'bytesPosted' => 0); $path = utils::normalize(__DIR__ . "/../data/{$identifier}.json"); if (file_put_contents($path, json_encode($data)) === false) { return new Response('', Response::HTTP_INTERNAL_SERVER_ERROR, ['Content-Type' => 'text/plain']); } $result = utils::executeScript("/dl.php lmv:dl {$identifier}"); if ($result === false) { return new Response('', Response::HTTP_INTERNAL_SERVER_ERROR, ['Content-Type' => 'text/plain']); } $data = (object) array('status' => $identifier); return new JsonResponse($data, Response::HTTP_OK); }
public function thumbnail($urn, $width = null, $height = null) { $encodedURN = base64_encode($urn); $config = lmv::config(); $endpoint = sprintf($config['getThumbnailsEndPoint'], $encodedURN); $query = []; if ($width !== null) { $query['width'] = $width; } if ($height !== null) { $query['height'] = $height; } Unirest\Request::verifyPeer(false); $response = Unirest\Request::get($endpoint, array('Authorization' => 'Bearer ' . lmv::bearer()), $query); if ($response->code != lmv::HTTP_OK) { utils::log('thumbnail fail ' . $response->code); return null; } return $response->raw_body; }
/** * Register a cell number and respond with a token to be used as its identifier. * * @return Response */ public function verifyotp($cell, $otp) { $filters = Input::only('service', 'keymatch', 'otp_start'); if ($cell == '919090909090') { $vendor = new Vendor(); $token = $vendor->matchOTP($cell, '00000'); return $token; } if ($filters['service'] == 'cognalys') { // These code snippets use an open-source library. http://unirest.io/php $app_id = 'dfc143fef04f431eb535bd5'; $access_token = '6789863e2fa229edfb3e57251cca55d9a601e6ba'; #https://www.cognalys.com/api/v1/otp/?app_id=dfc143fef04f431eb535bd5&access_token=6789863e2fa229edfb3e57251cca55d9a601e6ba&mobile=+918750688382 $url = 'https://cognalys.p.mashape.com/confirm/?'; $url .= 'app_id=' . $app_id; $url .= '&access_token=' . $access_token; $url .= '&keymatch=' . $filters['keymatch']; $url .= '&otp=' . $filters['otp_start'] . $otp; \Unirest\Request::verifyPeer(false); $result = \Unirest\Request::get($url, array("X-Mashape-Key" => "ehq1KAY8TemshmrDN3lvqKdMiPiAp11jxqijsnJp2pqiVjIMIL", "Accept" => "application/json")); $json = $result->body; if ($json->status == 'failed') { $retval = []; $retval['token'] = 'undef'; $retval['service_response'] = $json->errors; $retval['url'] = $url; return $retval; } else { $vendor = new Vendor(); $token = $vendor->matchOTP($cell, $filters['otp_start']); return $token; } } else { $vendor = new Vendor(); $token = $vendor->matchOTP($cell, $otp); return $token; } }
protected function DownloadFileAndSaveItemToDisk($item) { try { Unirest\Request::verifyPeer(false); $response = Unirest\Request::get($item, array('Authorization' => 'Bearer ' . lmv::bearer()), null); //$filename =basename ($item) ; $fullpath = $this->lmv->dataDir("/{$this->identifier}/" . utils::postStr('/viewers/', $item)); $filepath = dirname($fullpath); if ($response->code != Response::HTTP_OK) { if ($response->code == Response::HTTP_NOT_FOUND || $response->code == Response::HTTP_GATEWAY_TIMEOUT) { utils::log("Error {$response->code} - {$item} <ignoring>"); utils::log("Download failed for {$fullpath}"); return (object) array('urn' => $item, 'name' => utils::postStr('/data/', $fullpath), 'size' => 0, 'dl' => 0, 'error' => $response->code); } utils::log("Download failed for {$urn}"); throw new \Exception($response->code); } $filesystem = new Filesystem(); $filesystem->mkdir($filepath); $this->mgr->dlProgressIntermediate((object) array('urn' => $item, 'name' => utils::postStr('/data/', $fullpath), 'size' => strlen($response->raw_body), 'dl' => strlen($response->raw_body))); if (file_put_contents($fullpath, $response->raw_body) === false) { throw new \Exception("file_put_contents ({$fullpath})"); } return (object) array('urn' => $item, 'name' => utils::postStr('/data/', $fullpath), 'size' => strlen($response->raw_body), 'dl' => strlen($response->raw_body)); } catch (Exception $err) { utils::log('DownloadFileAndSaveItemToDisk exception ' . $err->getMessage()); utils::log("Save to disk failed for {$item}"); throw $err; } }
/** * Execute the job. * * @return void */ public function handle() { HTTPRequest::verifyPeer(env('UNIREST_VERIFYPEER')); $response = HTTPRequest::get($this->url); $posts = $response->body->data->children; foreach ($posts as $post) { // dd($post->data->stickied); if (!$post->data->stickied) { Quote::firstorCreate(["content" => $post->data->title, "author" => $post->data->author, "source" => 'https://www.reddit.com' . $post->data->permalink]); } } }