本文整理汇总了PHP中curl_setopt_array函数的典型用法代码示例。如果您正苦于以下问题:PHP curl_setopt_array函数的具体用法?PHP curl_setopt_array怎么用?PHP curl_setopt_array使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了curl_setopt_array函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Sender constructor.
* @param $url
*/
public function __construct($url)
{
$this->curlHandler = curl_init();
curl_setopt_array($this->curlHandler, $this->curlOptions);
curl_setopt($this->curlHandler, CURLOPT_URL, $url);
return $this;
}
示例2: curlConnection
private function curlConnection($method = 'GET', $url, array $data = null, $timeout, $charset)
{
if (strtoupper($method) === 'POST') {
$postFields = $data ? http_build_query($data, '', '&') : "";
$contentLength = "Content-length: " . strlen($postFields);
$methodOptions = array(CURLOPT_POST => true, CURLOPT_POSTFIELDS => $postFields);
} else {
$contentLength = null;
$methodOptions = array(CURLOPT_HTTPGET => true);
}
$options = array(CURLOPT_HTTPHEADER => array("Content-Type: application/x-www-form-urlencoded; charset=" . $charset, $contentLength), CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_CONNECTTIMEOUT => $timeout);
$options = $options + $methodOptions;
$curl = curl_init();
curl_setopt_array($curl, $options);
$resp = curl_exec($curl);
$info = curl_getinfo($curl);
$error = curl_errno($curl);
$errorMessage = curl_error($curl);
curl_close($curl);
$this->setStatus((int) $info['http_code']);
$this->setResponse((string) $resp);
if ($error) {
throw new Exception("CURL can't connect: {$errorMessage}");
return false;
} else {
return true;
}
}
示例3: getDom
public function getDom($url, $post = false)
{
$f = fopen(CURL_LOG_FILE, 'a+');
// curl session log file
if ($this->lastUrl) {
$header[] = "Referer: {$this->lastUrl}";
}
$curlOptions = array(CURLOPT_ENCODING => 'gzip,deflate', CURLOPT_AUTOREFERER => 1, CURLOPT_CONNECTTIMEOUT => 120, CURLOPT_TIMEOUT => 120, CURLOPT_URL => $url, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => 9, CURLOPT_RETURNTRANSFER => 1, CURLOPT_HEADER => 0, CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36", CURLOPT_COOKIEFILE => COOKIE_FILE, CURLOPT_COOKIEJAR => COOKIE_FILE, CURLOPT_STDERR => $f, CURLOPT_VERBOSE => true);
if ($post) {
// add post options
$curlOptions[CURLOPT_POSTFIELDS] = $post;
$curlOptions[CURLOPT_POST] = true;
}
$curl = curl_init();
curl_setopt_array($curl, $curlOptions);
$data = curl_exec($curl);
$this->lastUrl = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL);
// get url we've been redirected to
curl_close($curl);
if ($this->dom) {
$this->dom->clear();
$this->dom = false;
}
$dom = $this->dom = str_get_html($data);
fwrite($f, "{$post}\n\n");
fwrite($f, "-----------------------------------------------------------\n\n");
fclose($f);
return $dom;
}
示例4: call
public function call($data)
{
if ($this->config->get('pp_express_test') == 1) {
$api_endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
$user = $this->config->get('pp_express_sandbox_username');
$password = $this->config->get('pp_express_sandbox_password');
$signature = $this->config->get('pp_express_sandbox_signature');
} else {
$api_endpoint = 'https://api-3t.paypal.com/nvp';
$user = $this->config->get('pp_express_username');
$password = $this->config->get('pp_express_password');
$signature = $this->config->get('pp_express_signature');
}
$settings = array('USER' => $user, 'PWD' => $password, 'SIGNATURE' => $signature, 'VERSION' => '109.0', 'BUTTONSOURCE' => 'Code4Fun_2.0_EC');
$this->log($data, 'Call data');
$defaults = array(CURLOPT_POST => 1, CURLOPT_HEADER => 0, CURLOPT_URL => $api_endpoint, CURLOPT_USERAGENT => "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1", CURLOPT_FRESH_CONNECT => 1, CURLOPT_RETURNTRANSFER => 1, CURLOPT_FORBID_REUSE => 1, CURLOPT_TIMEOUT => 0, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_POSTFIELDS => http_build_query(array_merge($data, $settings), '', "&"));
$ch = curl_init();
curl_setopt_array($ch, $defaults);
if (!($result = curl_exec($ch))) {
$this->log(array('error' => curl_error($ch), 'errno' => curl_errno($ch)), 'cURL failed');
}
$this->log($result, 'Result');
curl_close($ch);
return $this->cleanReturn($result);
}
示例5: call_elucidat
/**
* Makes an API request to elucidat
* @param $headers
* @param $fields
* @param $url
* @param $consumer_secret
* @return mixed
*/
function call_elucidat($headers, $fields, $method, $url, $consumer_secret)
{
//Build a signature
$headers['oauth_signature'] = build_signature($consumer_secret, array_merge($headers, $fields), $method, $url);
//Build OAuth headers
$auth_headers = 'Authorization:';
$auth_headers .= build_base_string($headers, ',');
//Build the request string
$fields_string = build_base_string($fields, '&');
//Set the headers
$header = array($auth_headers, 'Expect:');
// Create curl options
if (strcasecmp($method, "GET") == 0) {
$url .= '?' . $fields_string;
$options = array(CURLOPT_HTTPHEADER => $header, CURLOPT_HEADER => false, CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false);
} else {
$options = array(CURLOPT_HTTPHEADER => $header, CURLOPT_HEADER => false, CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_POST => count($fields), CURLOPT_POSTFIELDS => $fields_string);
}
//Init the request and set its params
$request = curl_init();
curl_setopt_array($request, $options);
//Make the request
$response = curl_exec($request);
$status = curl_getinfo($request, CURLINFO_HTTP_CODE);
curl_close($request);
return array('status' => $status, 'response' => json_decode($response, true));
}
示例6: curl_setopt_array
function curl_setopt_array($handle, array $options)
{
if (array_values($options) != [null, null, null, null]) {
$_SERVER['last_curl'] = $options;
}
\curl_setopt_array($handle, $options);
}
示例7: remote
/**
* Returns the output of a remote URL. Any [curl option](http://php.net/curl_setopt)
* may be used.
*
* // Do a simple GET request
* $data = Remote::get($url);
*
* // Do a POST request
* $data = Remote::get($url, array(
* CURLOPT_POST => true,
* CURLOPT_POSTFIELDS => http_build_query($array),
* ));
*
* @param string remote URL
* @param array curl options
* @return string
* @throws Exception
*/
public static function remote($url, array $options = null)
{
// The transfer must always be returned
$options[CURLOPT_RETURNTRANSFER] = true;
// Open a new remote connection
$remote = curl_init($url);
// Set connection options
if (!curl_setopt_array($remote, $options)) {
throw new Exception('Failed to set CURL options, check CURL documentation: http://php.net/curl_setopt_array');
}
// Get the response
$response = curl_exec($remote);
// Get the response information
$code = curl_getinfo($remote, CURLINFO_HTTP_CODE);
if ($code and ($code < 200 or $code > 299)) {
$error = $response;
} elseif ($response === false) {
$error = curl_error($remote);
}
// Close the connection
curl_close($remote);
if (isset($error)) {
throw new Exception(sprintf('Error fetching remote %s [ status %s ] %s', $url, $code, $error));
}
return $response;
}
示例8: setup
public static function setup($client_id, $client_secret, $podio_username, $podio_password, $options = array('session_manager' => null, 'curl_options' => array()))
{
// Setup client info
self::$client_id = $client_id;
self::$client_secret = $client_secret;
// Setup curl
self::$url = empty($options['api_url']) ? 'https://api.podio.com:443' : $options['api_url'];
self::$debug = self::$debug ? self::$debug : false;
self::$ch = curl_init();
self::$headers = array('Accept' => 'application/json');
curl_setopt(self::$ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt(self::$ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt(self::$ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt(self::$ch, CURLOPT_USERAGENT, 'Podio PHP Client/' . self::VERSION);
curl_setopt(self::$ch, CURLOPT_HEADER, true);
curl_setopt(self::$ch, CURLINFO_HEADER_OUT, true);
if ($options && !empty($options['curl_options'])) {
curl_setopt_array(self::$ch, $options['curl_options']);
}
if (!Cache::has('podio_oauth')) {
self::authenticate_with_password($podio_username, $podio_password);
Cache::put('podio_oauth', Podio::$oauth, 480);
self::$oauth = Cache::get('podio_oauth');
}
// Register shutdown function for debugging and session management
register_shutdown_function('Podio::shutdown');
}
示例9: call
private function call()
{
$curl = array(CURLOPT_POST => 0, CURLOPT_HEADER => 0, CURLOPT_URL => 'http://www.marketinsg.com/index.php?route=information/news/system&url=' . rawurlencode(HTTP_CATALOG), CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1', CURLOPT_FRESH_CONNECT => 1, CURLOPT_RETURNTRANSFER => 1, CURLOPT_FORBID_REUSE => 1, CURLOPT_TIMEOUT => 0, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_SSL_VERIFYHOST => 0);
$ch = curl_init();
curl_setopt_array($ch, $curl);
if (!($result = curl_exec($ch))) {
curl_close($ch);
exit;
}
curl_close($ch);
$encoding = mb_detect_encoding($result);
if ($encoding == 'UTF-8') {
$result = preg_replace('/[^(\\x20-\\x7F)]*/', '', $result);
}
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "marketinsg_news WHERE text ='" . $this->db->escape($result) . "'");
if (!$query->num_rows) {
$this->db->query("DELETE FROM " . DB_PREFIX . "marketinsg_news");
$this->db->query("INSERT INTO " . DB_PREFIX . "marketinsg_news SET text ='" . $this->db->escape($result) . "', date_added = NOW()");
}
$disabled = '[{"title":"<strong>You have been disabled from MarketInSG.com news system<\\/strong>"}]';
if (addslashes($result) == addslashes($disabled)) {
$this->db->query("INSERT INTO " . DB_PREFIX . "marketinsg_news_log SET date_checked = NOW(), status = 0");
} else {
$this->db->query("INSERT INTO " . DB_PREFIX . "marketinsg_news_log SET date_checked = NOW(), status = 1");
}
}
示例10: getContent
/**
* {@inheritDoc}
*/
public function getContent($url)
{
if (!function_exists('curl_init')) {
throw new ExtensionNotLoadedException('cURL has to be enabled.');
}
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $url);
if ($this->timeout) {
curl_setopt($c, CURLOPT_TIMEOUT, $this->timeout);
}
if ($this->connectTimeout) {
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
}
if ($this->userAgent) {
curl_setopt($c, CURLOPT_USERAGENT, $this->userAgent);
}
if ($this->options && is_array($this->options) && count($this->options) > 0) {
curl_setopt_array($c, $this->options);
}
$content = curl_exec($c);
curl_close($c);
if (false === $content) {
$content = null;
}
return $content;
}
示例11: requestApi
/**
* {@inheritdoc}
*/
public function requestApi($apiUrl, $params = array(), $method = 'POST')
{
$curlOpts = array(CURLOPT_URL => $apiUrl, CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => $method, CURLOPT_USERAGENT => 'payrexx-php/1.0.0', CURLOPT_SSL_VERIFYPEER => true, CURLOPT_CAINFO => dirname(__DIR__) . '/certs/ca.pem');
$paramString = http_build_query($params, null, '&', PHP_QUERY_RFC3986);
if ($method == 'GET') {
if (!empty($params)) {
$curlOpts[CURLOPT_URL] .= strpos($curlOpts[CURLOPT_URL], '?') === false ? '?' : '&';
$curlOpts[CURLOPT_URL] .= $paramString;
}
} else {
$curlOpts[CURLOPT_POSTFIELDS] = $paramString;
$curlOpts[CURLOPT_URL] .= strpos($curlOpts[CURLOPT_URL], '?') === false ? '?' : '&';
$curlOpts[CURLOPT_URL] .= 'instance=' . $params['instance'];
}
$curl = curl_init();
curl_setopt_array($curl, $curlOpts);
$responseBody = $this->curlExec($curl);
$responseInfo = $this->curlInfo($curl);
if ($responseBody === false) {
$responseBody = array('status' => 'error', 'message' => $this->curlError($curl));
}
curl_close($curl);
if ($responseInfo['content_type'] != 'application/json') {
return $responseBody;
}
return json_decode($responseBody, true);
}
示例12: execute
public function execute()
{
$mh = curl_multi_init();
$conn = [];
foreach ($this->getUrls() as $k => $url) {
$this->setOption(CURLOPT_URL, $url);
$ch = curl_init();
curl_setopt_array($ch, $this->getOptions());
$conn[$k] = $ch;
curl_multi_add_handle($mh, $conn[$k]);
}
$active = false;
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
while ($active && $mrc == CURLM_OK) {
if (curl_multi_select($mh) != -1) {
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
}
$res = [];
foreach ($this->getUrls() as $k => $url) {
$res[$k] = curl_multi_getcontent($conn[$k]);
curl_close($conn[$k]);
curl_multi_remove_handle($mh, $conn[$k]);
}
curl_multi_close($mh);
return $res;
}
示例13: sendRequest
public static function sendRequest($host, array $fields, $method = 'get', $extra_curl = [])
{
$curl = curl_init();
switch (strtolower($method)) {
case 'get':
$curl_params = [CURLOPT_URL => $host . '?' . http_build_query($fields), CURLOPT_RETURNTRANSFER => 1] + $extra_curl;
curl_setopt_array($curl, $curl_params);
break;
case 'post':
$curl_params = [CURLOPT_POST => true, CURLOPT_URL => $host, CURLOPT_HTTPAUTH => CURLAUTH_ANY, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_RETURNTRANSFER => 1, CURLOPT_HEADER => false, CURLOPT_POSTFIELDS => http_build_query($fields)] + $extra_curl;
curl_setopt_array($curl, $curl_params);
break;
}
$result = curl_exec($curl);
if (!$result) {
throw new \Exception(curl_errno($curl));
}
$json = json_decode($result, true);
if ($json) {
$output = $json;
} else {
parse_str($result, $output);
}
// if the result is not a valid json, it might be a string to be parsed
if (isset($output['error'])) {
//throw new \Exception( $output['error_message']);
var_dump($output);
exit;
}
return $output;
}
示例14: request
/**
* Perform InfluxDB request
*
* @param string $uri
* @param Query $query
* @param JsonSerializable $postData
*
* @return mixed
*/
public function request($uri, Query $query, JsonSerializable $postData = null)
{
$params = clone $query;
$params->addQueryPart('u', $this->username);
$params->addQueryPart('p', $this->password);
$url = "http://{$this->host}:{$this->port}{$uri}?" . http_build_query($params->getArrayCopy());
$ch = curl_init($url);
curl_setopt_array($ch, array(CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true));
if ($postData !== null) {
curl_setopt_array($ch, array(CURLOPT_POST => true, CURLOPT_POSTFIELDS => json_encode($postData), CURLOPT_HTTPHEADER => array('Content-Type: application/json')));
}
$response = curl_exec($ch);
$info = curl_getinfo($ch);
if ($info['http_code'] !== 200) {
if ($response === false) {
throw new Exception\InvalidApiResponse('Empty Response Body', $info['http_code']);
}
$result = json_decode($response, true);
if (is_array($result) === false) {
throw new Exception\InvalidApiResponse('Invalid Response Body', $info['http_code'], null, $response);
}
if (array_key_exists('error', $result) === true) {
throw new Exception\ApiError($result['error']);
}
}
// Decode result
$result = json_decode($response, true);
// Return results
return $result['results'];
}
示例15: curlExec
function curlExec($base_url)
{
$ch = curl_init($base_url);
curl_setopt_array($ch, array(CURLOPT_URL => $base_url, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_TIMEOUT => 30, CURLOPT_USERAGENT => 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)', CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_SSL_VERIFYHOST => 0));
$results = curl_exec($ch);
return $results;
}