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


PHP Http::set_error方法代码示例

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


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

示例1: request


//.........这里部分代码省略.........
     switch ($args['method']) {
         case 'HEAD':
             curl_setopt($handle, CURLOPT_NOBODY, true);
             break;
         case 'POST':
             curl_setopt($handle, CURLOPT_POST, true);
             curl_setopt($handle, CURLOPT_POSTFIELDS, $args['body']);
             break;
         case 'PUT':
             curl_setopt($handle, CURLOPT_CUSTOMREQUEST, 'PUT');
             curl_setopt($handle, CURLOPT_POSTFIELDS, $args['body']);
             break;
         default:
             curl_setopt($handle, CURLOPT_CUSTOMREQUEST, $args['method']);
             if (!is_null($args['body'])) {
                 curl_setopt($handle, CURLOPT_POSTFIELDS, $args['body']);
             }
             break;
     }
     if ($args['blocking'] === true) {
         curl_setopt($handle, CURLOPT_HEADERFUNCTION, array($this, 'stream_headers'));
         curl_setopt($handle, CURLOPT_WRITEFUNCTION, array($this, 'stream_body'));
     }
     curl_setopt($handle, CURLOPT_HEADER, false);
     if (isset($args['limit_response_size'])) {
         $this->max_body_length = intval($args['limit_response_size']);
     } else {
         $this->max_body_length = false;
     }
     // If streaming to a file open a file handle, and setup our curl streaming handler
     if ($args['stream']) {
         $this->stream_handle = @fopen($args['filename'], 'w+');
         if (!$this->stream_handle) {
             Http::set_error(10);
             return $this;
         }
     } else {
         $this->stream_handle = false;
     }
     if (!empty($args['headers'])) {
         // cURL expects full header strings in each element
         $headers = array();
         foreach ($args['headers'] as $name => $value) {
             $headers[] = "{$name}: {$value}";
         }
         curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
     }
     if ($args['httpversion'] == '1.0') {
         curl_setopt($handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
     } else {
         curl_setopt($handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
     }
     // We don't need to return the body, so don't. Just execute request and return.
     if (!$args['blocking']) {
         curl_exec($handle);
         if ($curl_error = curl_error($handle)) {
             curl_close($handle);
             Http::set_error(11);
             return $this;
         }
         if (in_array(curl_getinfo($handle, CURLINFO_HTTP_CODE), array(301, 302))) {
             curl_close($handle);
             Http::set_error(5);
             return $this;
         }
         curl_close($handle);
开发者ID:nukeplus,项目名称:nuke,代码行数:67,代码来源:Curl.php

示例2: request

 /**
  *
  * @param mixed $url
  * @param mixed $args
  * @return
  */
 public function request($url, $args = array())
 {
     $defaults = array('method' => 'GET', 'timeout' => 5, 'redirection' => 5, 'httpversion' => '1.0', 'blocking' => true, 'headers' => array(), 'body' => null, 'cookies' => array());
     $args = Http::build_args($args, $defaults);
     // Get user agent
     if (isset($args['headers']['User-Agent'])) {
         $args['user-agent'] = $args['headers']['User-Agent'];
         unset($args['headers']['User-Agent']);
     } elseif (isset($args['headers']['user-agent'])) {
         $args['user-agent'] = $args['headers']['user-agent'];
         unset($args['headers']['user-agent']);
     }
     // Get Referer
     if (isset($args['headers']['Referer'])) {
         $args['referer'] = $args['headers']['Referer'];
         unset($args['headers']['Referer']);
     } elseif (isset($args['headers']['referer'])) {
         $args['referer'] = $args['headers']['referer'];
         unset($args['headers']['referer']);
     }
     // Construct Cookie: header if any cookies are set
     Http::buildCookieHeader($args);
     $arrURL = parse_url($url);
     $connect_host = $arrURL['host'];
     $secure_transport = ($arrURL['scheme'] == 'ssl' or $arrURL['scheme'] == 'https');
     if (!isset($arrURL['port'])) {
         if ($arrURL['scheme'] == 'ssl' or $arrURL['scheme'] == 'https') {
             $arrURL['port'] = 443;
             $secure_transport = true;
         } else {
             $arrURL['port'] = 80;
         }
     }
     if (isset($args['headers']['Host']) or isset($args['headers']['host'])) {
         if (isset($args['headers']['Host'])) {
             $arrURL['host'] = $args['headers']['Host'];
         } else {
             $arrURL['host'] = $args['headers']['host'];
         }
         unset($args['headers']['Host'], $args['headers']['host']);
     }
     // Certain versions of PHP have issues with 'localhost' and IPv6, It attempts to connect to ::1,
     // which fails when the server is not set up for it. For compatibility, always connect to the IPv4 address.
     if (strtolower($connect_host) == 'localhost') {
         $connect_host = '127.0.0.1';
     }
     $connect_host = $secure_transport ? 'ssl://' . $connect_host : 'tcp://' . $connect_host;
     $is_local = isset($args['local']) and $args['local'];
     $ssl_verify = isset($args['sslverify']) and $args['sslverify'];
     // NukeViet has no proxy setup
     $context = stream_context_create(array('ssl' => array('verify_peer' => $ssl_verify, 'capture_peer_cert' => $ssl_verify, 'SNI_enabled' => true, 'cafile' => $args['sslcertificates'], 'allow_self_signed' => !$ssl_verify)));
     $timeout = (int) floor($args['timeout']);
     $utimeout = $timeout == $args['timeout'] ? 0 : 1000000 * $args['timeout'] % 1000000;
     $connect_timeout = max($timeout, 1);
     $connection_error = null;
     // Store error number
     $connection_error_str = null;
     // Store error string
     // In the event that the SSL connection fails, silence the many PHP Warnings
     if ($secure_transport) {
         $error_reporting = error_reporting(0);
     }
     // No proxy option on NukeViet, maybe in future!!!!
     //if( $proxy->is_enabled() and $proxy->send_through_proxy( $url ) )
     //{
     //	$handle = @stream_socket_client( 'tcp://' . $proxy->host() . ':' . $proxy->port(), $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context );
     //}
     //else
     //{
     $handle = @stream_socket_client($connect_host . ':' . $arrURL['port'], $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context);
     //}
     if ($secure_transport) {
         error_reporting($error_reporting);
     }
     if ($handle === false) {
         // SSL connection failed due to expired/invalid cert, or, OpenSSL configuration is broken
         if ($secure_transport and $connection_error === 0 and $connection_error_str === '') {
             Http::set_error(6);
             return false;
         }
         Http::set_error(7);
         return false;
     }
     // Verify that the SSL certificate is valid for this request
     if ($secure_transport and $ssl_verify) {
         if (!self::verify_ssl_certificate($handle, $arrURL['host'])) {
             Http::set_error(6);
             return false;
         }
     }
     stream_set_timeout($handle, $timeout, $utimeout);
     //if( $proxy->is_enabled() and $proxy->send_through_proxy( $url ) )
     //{
     //	//Some proxies require full URL in this field.
//.........这里部分代码省略.........
开发者ID:nukeplus,项目名称:nuke,代码行数:101,代码来源:Streams.php


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