本文整理汇总了PHP中curl_errno函数的典型用法代码示例。如果您正苦于以下问题:PHP curl_errno函数的具体用法?PHP curl_errno怎么用?PHP curl_errno使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了curl_errno函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: query
public function query($method, $parameters = null)
{
$request = xmlrpc_encode_request($method, $parameters);
$headers = array("Content-type: text/xml", "Content-length: " . strlen($request));
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $this->url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
if ($this->timeout) {
curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout);
}
$rawResponse = curl_exec($curl);
$curlErrno = curl_errno($curl);
$curlError = curl_error($curl);
curl_close($curl);
if ($curlErrno) {
throw new NetworkException($curlError, $curlErrno);
}
$result = xmlrpc_decode($rawResponse);
if (xmlrpc_is_fault($result)) {
throw new NetworkException($result['faultString'], $result['faultCode']);
}
return $result;
}
示例2: makeRequest
/**
* 执行一个 HTTP 请求
*
* @param string $url 执行请求的URL
* @param mixed $params 表单参数
* 可以是array, 也可以是经过url编码之后的string
* @param mixed $cookie cookie参数
* 可以是array, 也可以是经过拼接的string
* @param string $method 请求方法 post / get
* @param string $protocol http协议类型 http / https
* @return array 结果数组
*/
public static function makeRequest($url, $params, $cookie, $method = 'post', $protocol = 'http')
{
$query_string = self::makeQueryString1($params);
$cookie_string = self::makeCookieString($cookie);
$ch = curl_init();
if ('get' == $method) {
curl_setopt($ch, CURLOPT_URL, "{$url}?{$query_string}");
} else {
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);
}
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
// disable 100-continue
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
if (!empty($cookie_string)) {
curl_setopt($ch, CURLOPT_COOKIE, $cookie_string);
}
if ('https' == $protocol) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
$ret = curl_exec($ch);
$err = curl_error($ch);
if (false === $ret || !empty($err)) {
$errno = curl_errno($ch);
$info = curl_getinfo($ch);
curl_close($ch);
return array('result' => false, 'errno' => $errno, 'msg' => $err, 'info' => $info);
}
curl_close($ch);
return array('result' => true, 'msg' => $ret);
}
示例3: curlRequest
function curlRequest($ip, $name)
{
$qs = 'http://' . $this->service . '/' . $this->version . '/' . $name . '/' . '?ip=' . $ip . '&format=json&key=' . $this->apiKey;
$app = JFactory::getApplication();
if (!function_exists('curl_init')) {
//$app->enqueueMessage('The AcyMailing geolocation plugin needs the CURL library installed but it seems that it is not available on your server. Please contact your web hosting to set it up.','error');
$this->errors[] = 'The AcyMailing geolocation plugin needs the CURL library installed but it seems that it is not available on your server. Please contact your web hosting to set it up.';
return false;
}
if (!function_exists('json_decode')) {
//$app->enqueueMessage('The AcyMailing geolocation plugin can only work with PHP 5.2 at least. Please ask your web hosting to update your PHP version','error');
$this->errors[] = 'The AcyMailing geolocation plugin can only work with PHP 5.2 at least. Please ask your web hosting to update your PHP version';
return false;
}
if (!isset($this->curl)) {
$this->curl = curl_init();
curl_setopt($this->curl, CURLOPT_FAILONERROR, TRUE);
if (@ini_get('open_basedir') == '' && @ini_get('safe_mode' == 'Off')) {
curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, TRUE);
}
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT, $this->timeout);
curl_setopt($this->curl, CURLOPT_TIMEOUT, $this->timeout);
}
curl_setopt($this->curl, CURLOPT_URL, $qs);
$json = curl_exec($this->curl);
if (curl_errno($this->curl) || $json === FALSE) {
$this->errors[] = 'cURL failed. Error: ' . curl_error($this->curl);
//$app->enqueueMessage('cURL failed. Error: ' . $err);
return false;
}
$response = json_decode($json);
return $response;
}
示例4: 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;
}
}
示例5: send
function send()
{
//check the fields to make sure that they are not NULL
$this->isComplete();
$url = $this->host . $this->postPath;
$postBody = json_encode($this->data);
$sign = md5("POST" . $url . $postBody . $this->appMasterSecret);
$url = $url . "?sign=" . $sign;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postBody);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curlErrNo = curl_errno($ch);
$curlErr = curl_error($ch);
curl_close($ch);
//print($result . "\r\n");
if ($httpCode == "0") {
// Time out
throw new Exception("Curl error number:" . $curlErrNo . " , Curl error details:" . $curlErr . "\r\n");
} else {
if ($httpCode != "200") {
// We did send the notifition out and got a non-200 response
throw new Exception("Http code:" . $httpCode . " details:" . $result . "\r\n");
} else {
return $result;
}
}
}
示例6: fetch_json
/**
* Fetch JSON data from an HTTP endpoint
*
* Parameters
* $hostname - the hostname of the endpoint
* $port - the port to connect to
* $protocol - the protocol used (http or https)
* $url - the endpoint url on the host
*
* Return an array of the form
* [ "errors" => true/false, "details" => "json_decoded data",
* "curl_stats" => "stats from the curl call"]
*/
static function fetch_json($hostname, $port, $protocol, $url)
{
$ch = curl_init("{$protocol}://{$hostname}:{$port}{$url}");
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$json = curl_exec($ch);
$info = curl_getinfo($ch);
$ret = ["errors" => false];
if (curl_errno($ch)) {
$errmsg = "Attempt to hit API failed, sorry. ";
$errmsg .= "Curl said: " . curl_error($ch);
return ["errors" => true, "details" => $errmsg];
} elseif ($info['http_code'] != 200) {
$errmsg = "Attempt to hit API failed, sorry. ";
$errmsg .= "Curl said: HTTP Status {$info['http_code']}";
return ["errors" => true, "details" => $errmsg];
} else {
$ret["curl_stats"] = ["{$hostname}:{$port}" => curl_getinfo($ch)];
$ret["details"] = json_decode($json, true);
}
curl_close($ch);
return $ret;
}
示例7: pdt
public function pdt($txn)
{
$params = array('at' => $this->atPaypal, 'tx' => $txn, 'cmd' => '_notify-synch');
$content = '';
foreach ($params as $key => $val) {
$content .= '&' . $key . '=' . urlencode($val);
}
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $this->paypalEndpoint);
curl_setopt($c, CURLOPT_VERBOSE, TRUE);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, $content);
$response = curl_exec($c);
if (!$response) {
echo "FAILED: " . curl_error($c) . "(" . curl_errno($c) . ")";
curl_close($c);
return false;
} else {
$str = urldecode($response);
$res = explode("\n", strip_tags($str));
$result = array();
foreach ($res as $val) {
$r = explode("=", $val);
if (count($r) > 1) {
$result[$r[0]] = $r[1];
}
}
curl_close($c);
return $result;
}
}
示例8: getUrl
function getUrl($url)
{
$this->lastUrl = $url;
//echo "GET $url \n";
// Faire un get mais en fournissant les cookies de session et tout ...
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPGET, 1);
//curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie_file);
// pour envoi des cookies
curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookie_file);
// pour reception des cookies
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; U; Linux i686; fr; rv:1.9.1.1) Gecko/20090715 Firefox/3.5.1");
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$redirect = 0;
$getResult = $this->curl_redirect_exec($ch, $redirect);
//echo "$redirect redirection ! \n";
if (curl_errno($ch)) {
print curl_error($ch);
}
curl_close($ch);
return $getResult;
}
示例9: doRequest
/**
* @return array
* @throws Payone_Api_Exception_InvalidResponse
*/
protected function doRequest()
{
$response = array();
$urlArray = $this->generateUrlArray();
$urlHost = $urlArray['host'];
$urlPath = isset($urlArray['path']) ? $urlArray['path'] : '';
$urlScheme = $urlArray['scheme'];
$urlQuery = $urlArray['query'];
$curl = curl_init($urlScheme . "://" . $urlHost . $urlPath);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $urlQuery);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_TIMEOUT, self::DEFAULT_TIMEOUT);
$result = curl_exec($curl);
$this->setRawResponse($result);
if (curl_getinfo($curl, CURLINFO_HTTP_CODE) != 200) {
throw new Payone_Api_Exception_InvalidResponse();
} elseif (curl_error($curl)) {
$response[] = "errormessage=" . curl_errno($curl) . ": " . curl_error($curl);
} else {
$response = explode("\n", $result);
}
curl_close($curl);
return $response;
}
示例10: command
protected function command($cmd, $request)
{
$param = '<' . $this->type . ' id="1" res="request" cmd="' . $cmd . '"';
$request['account'] = empty($request['account']) ? $this->getUsername() : $request['account'];
$request['pwd_user'] = empty($request['pwd_user']) ? $this->getPassword() : $request['pwd_user'];
if (!empty($request)) {
foreach ($request as $key => $value) {
$param .= ' ' . $key . '="' . $value . '"';
}
}
$param .= "/>";
$xml = '<?xml version="1.0" standalone="yes"?><root>' . $param . '</root>';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $this->url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
$response = curl_exec($curl);
if (!curl_errno($curl)) {
$info = curl_getinfo($curl);
//echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'];
} else {
throw new \Exception(curl_error($curl));
}
return simplexml_load_string($response);
}
示例11: callApi
public static function callApi($url, $auth_token, $method = 'POST', $data = null)
{
$headers = array("Accept: application/json", "Content-Type: application/json");
if ($auth_token) {
$headers[] = "Authorization: OAuth oauth_token={$auth_token}";
}
$json_data = false;
if (is_array($data)) {
$json_data = json_encode($data);
$headers[] = "Content-Length: " . strlen($json_data);
}
$request = HttpRequest::request($url, $method, $json_data, $headers);
if ($request) {
$results = json_decode($request);
if (isset($results->int_err_code)) {
throw new \ErrorException('There was an error returned from the API: ' . $results->msg . ' (' . $results->int_err_code . ')', 160);
} elseif (isset($results->err)) {
throw new \ErrorException('There was an error returned from the API: ' . $results->message . ' (' . $results->err . ')', 160);
} else {
return $results;
}
} else {
$error = "API call returned an HTTP status code of " . curl_errno($ch);
throw new \ErrorException($error, 107);
}
}
示例12: request
/**
* @inheritdoc
*/
public function request($action, array $getData = [], array $postData = [])
{
try {
$curlOptions = [CURLOPT_RETURNTRANSFER => true];
if ($postData) {
$json = json_encode($postData, JSON_PRETTY_PRINT);
if ($json === false) {
throw new RequesterException('Failed to serialize data into JSON. Data: ' . var_export($postData, true));
}
$curlOptions = $curlOptions + [CURLOPT_POSTFIELDS => $json, CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'Content-Length: ' . strlen($json)]];
}
$getParams = $getData ? '?' . http_build_query($getData) : '';
$curl = curl_init($this->endpoint->getUrl() . $action . $getParams);
curl_setopt_array($curl, $curlOptions);
$result = curl_exec($curl);
if ($result === false) {
throw new RequesterException(sprintf('cURL error: [%d] %s', curl_errno($curl), curl_error($curl)));
}
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
} catch (RequesterException $e) {
throw $e;
} catch (\Exception $e) {
$result = empty($result) ? '' : ', result: ' . $result;
throw new RequesterException('An error occurred during the transfer' . $result, null, $e);
}
if ($httpCode !== 200) {
throw new RequesterException(sprintf("Request resulted in HTTP code '%d'. Response result:\n%s", $httpCode, $result));
}
return new Response($result);
}
示例13: call
public function call($xml)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://test.ipg-online.com/ipgapi/services");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_HTTPAUTH, 'CURLAUTH_BASIC');
curl_setopt($ch, CURLOPT_USERPWD, $this->config->get('firstdata_remote_user_id') . ':' . $this->config->get('firstdata_remote_password'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_CAINFO, $this->config->get('firstdata_remote_ca'));
curl_setopt($ch, CURLOPT_SSLCERT, $this->config->get('firstdata_remote_certificate'));
curl_setopt($ch, CURLOPT_SSLKEY, $this->config->get('firstdata_remote_key'));
curl_setopt($ch, CURLOPT_SSLKEYPASSWD, $this->config->get('firstdata_remote_key_pw'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
//curl_setopt($ch, CURLOPT_STDERR, fopen(DIR_LOGS . "/headers.txt", "w+"));
curl_setopt($ch, CURLOPT_VERBOSE, true);
$response = curl_exec($ch);
$this->logger('Post data: ' . print_r($this->request->post, 1));
$this->logger('Request: ' . $xml);
$this->logger('Curl error #: ' . curl_errno($ch));
$this->logger('Curl error text: ' . curl_error($ch));
$this->logger('Curl response info: ' . print_r(curl_getinfo($ch), 1));
$this->logger('Curl response: ' . $response);
curl_close($ch);
return $response;
}
示例14: POST
public function POST($data)
{
$this->genPostData($data);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $this->url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $this->headers);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $this->postData);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$tmpInfo = curl_exec($curl);
if (curl_errno($curl)) {
print "[error] CURL ERROR: " . curl_error($curl) . "\r\n";
}
curl_close($curl);
$this->returnCode = ord($tmpInfo[0]) * 64 + ord($tmpInfo[1]);
if ($this->returnCode === 0) {
$this->retData = substr($tmpInfo, 8);
}
}
示例15: post_req
function post_req($url_str, $username, $password, $headers_arr, $req_str)
{
fwrite(STDERR, $url_str);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_str);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req_str);
// Don't get the headers
//curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_arr);
// execute the request
$output = curl_exec($ch);
$errno = curl_errno($ch);
$error = curl_error($ch);
if ($errno !== 0) {
curl_close($ch);
return array("success" => FALSE, "message" => "Error sending request to service {$url_str}: {$error}");
}
$sc_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($sc_code !== 200) {
$ct = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
curl_close($ch);
if (strcasecmp($ct, "application/json") == 0) {
$err_obj = json_decode($output, true);
return array("success" => FALSE, "message" => $err_obj['user_message']);
}
return array("success" => FALSE, "message" => "Service returned http code: {$sc_code}");
}
// close curl resource to free up system resources
curl_close($ch);
return array("success" => TRUE, "output" => $output);
}