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


PHP WP_HTTP_Proxy::authentication_header方法代码示例

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


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

示例1: request

 /**
  * Send a HTTP request to a URI using streams with fopen().
  *
  * @access public
  * @since 2.7.0
  *
  * @param string $url
  * @param str|array $args Optional. Override the defaults.
  * @return array 'headers', 'body', 'cookies' and 'response' keys.
  */
 function request($url, $args = array())
 {
     $defaults = array('method' => 'GET', 'timeout' => 5, 'redirection' => 5, 'httpversion' => '1.0', 'blocking' => true, 'headers' => array(), 'body' => null, 'cookies' => array());
     $r = wp_parse_args($args, $defaults);
     if (isset($r['headers']['User-Agent'])) {
         $r['user-agent'] = $r['headers']['User-Agent'];
         unset($r['headers']['User-Agent']);
     } else {
         if (isset($r['headers']['user-agent'])) {
             $r['user-agent'] = $r['headers']['user-agent'];
             unset($r['headers']['user-agent']);
         }
     }
     // Construct Cookie: header if any cookies are set
     WP_Http::buildCookieHeader($r);
     $arrURL = parse_url($url);
     if (false === $arrURL) {
         return new WP_Error('http_request_failed', sprintf(__('Malformed URL: %s'), $url));
     }
     if ('http' != $arrURL['scheme'] && 'https' != $arrURL['scheme']) {
         $url = preg_replace('|^' . preg_quote($arrURL['scheme'], '|') . '|', 'http', $url);
     }
     // Convert Header array to string.
     $strHeaders = '';
     if (is_array($r['headers'])) {
         foreach ($r['headers'] as $name => $value) {
             $strHeaders .= "{$name}: {$value}\r\n";
         }
     } else {
         if (is_string($r['headers'])) {
             $strHeaders = $r['headers'];
         }
     }
     $is_local = isset($args['local']) && $args['local'];
     $ssl_verify = isset($args['sslverify']) && $args['sslverify'];
     if ($is_local) {
         $ssl_verify = apply_filters('https_local_ssl_verify', $ssl_verify);
     } elseif (!$is_local) {
         $ssl_verify = apply_filters('https_ssl_verify', $ssl_verify);
     }
     $arrContext = array('http' => array('method' => strtoupper($r['method']), 'user_agent' => $r['user-agent'], 'max_redirects' => $r['redirection'], 'protocol_version' => (double) $r['httpversion'], 'header' => $strHeaders, 'timeout' => $r['timeout'], 'ssl' => array('verify_peer' => $ssl_verify, 'verify_host' => $ssl_verify)));
     $proxy = new WP_HTTP_Proxy();
     if ($proxy->is_enabled() && $proxy->send_through_proxy($url)) {
         $arrContext['http']['proxy'] = 'tcp://' . $proxy->host() . ':' . $proxy->port();
         $arrContext['http']['request_fulluri'] = true;
         // We only support Basic authentication so this will only work if that is what your proxy supports.
         if ($proxy->use_authentication()) {
             $arrContext['http']['header'] .= $proxy->authentication_header() . "\r\n";
         }
     }
     if (!is_null($r['body']) && !empty($r['body'])) {
         $arrContext['http']['content'] = $r['body'];
     }
     $context = stream_context_create($arrContext);
     if (!WP_DEBUG) {
         $handle = @fopen($url, 'r', false, $context);
     } else {
         $handle = fopen($url, 'r', false, $context);
     }
     if (!$handle) {
         return new WP_Error('http_request_failed', sprintf(__('Could not open handle for fopen() to %s'), $url));
     }
     // WordPress supports PHP 4.3, which has this function. Removed sanity checking for
     // performance reasons.
     stream_set_timeout($handle, $r['timeout']);
     if (!$r['blocking']) {
         stream_set_blocking($handle, 0);
         fclose($handle);
         return array('headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array());
     }
     $strResponse = stream_get_contents($handle);
     $meta = stream_get_meta_data($handle);
     fclose($handle);
     $processedHeaders = array();
     if (isset($meta['wrapper_data']['headers'])) {
         $processedHeaders = WP_Http::processHeaders($meta['wrapper_data']['headers']);
     } else {
         $processedHeaders = WP_Http::processHeaders($meta['wrapper_data']);
     }
     if (!empty($strResponse) && isset($processedHeaders['headers']['transfer-encoding']) && 'chunked' == $processedHeaders['headers']['transfer-encoding']) {
         $strResponse = WP_Http::chunkTransferDecode($strResponse);
     }
     if (true === $r['decompress'] && true === WP_Http_Encoding::should_decode($processedHeaders['headers'])) {
         $strResponse = WP_Http_Encoding::decompress($strResponse);
     }
     return array('headers' => $processedHeaders['headers'], 'body' => $strResponse, 'response' => $processedHeaders['response'], 'cookies' => $processedHeaders['cookies']);
 }
开发者ID:steveh,项目名称:wordpress,代码行数:97,代码来源:http.php

示例2: request


//.........这里部分代码省略.........
         return new WP_Error('http_request_failed', $connection_error . ': ' . $connection_error_str);
     }
     // Verify that the SSL certificate is valid for this request.
     if ($secure_transport && $ssl_verify && !$proxy->is_enabled()) {
         if (!self::verify_ssl_certificate($handle, $arrURL['host'])) {
             return new WP_Error('http_request_failed', __('The SSL certificate for the host could not be verified.'));
         }
     }
     stream_set_timeout($handle, $timeout, $utimeout);
     if ($proxy->is_enabled() && $proxy->send_through_proxy($url)) {
         //Some proxies require full URL in this field.
         $requestPath = $url;
     } else {
         $requestPath = $arrURL['path'] . (isset($arrURL['query']) ? '?' . $arrURL['query'] : '');
     }
     $strHeaders = strtoupper($r['method']) . ' ' . $requestPath . ' HTTP/' . $r['httpversion'] . "\r\n";
     $include_port_in_host_header = $proxy->is_enabled() && $proxy->send_through_proxy($url) || 'http' == $arrURL['scheme'] && 80 != $arrURL['port'] || 'https' == $arrURL['scheme'] && 443 != $arrURL['port'];
     if ($include_port_in_host_header) {
         $strHeaders .= 'Host: ' . $arrURL['host'] . ':' . $arrURL['port'] . "\r\n";
     } else {
         $strHeaders .= 'Host: ' . $arrURL['host'] . "\r\n";
     }
     if (isset($r['user-agent'])) {
         $strHeaders .= 'User-agent: ' . $r['user-agent'] . "\r\n";
     }
     if (is_array($r['headers'])) {
         foreach ((array) $r['headers'] as $header => $headerValue) {
             $strHeaders .= $header . ': ' . $headerValue . "\r\n";
         }
     } else {
         $strHeaders .= $r['headers'];
     }
     if ($proxy->use_authentication()) {
         $strHeaders .= $proxy->authentication_header() . "\r\n";
     }
     $strHeaders .= "\r\n";
     if (!is_null($r['body'])) {
         $strHeaders .= $r['body'];
     }
     fwrite($handle, $strHeaders);
     if (!$r['blocking']) {
         stream_set_blocking($handle, 0);
         fclose($handle);
         return array('headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array());
     }
     $strResponse = '';
     $bodyStarted = false;
     $keep_reading = true;
     $block_size = 4096;
     if (isset($r['limit_response_size'])) {
         $block_size = min($block_size, $r['limit_response_size']);
     }
     // If streaming to a file setup the file handle.
     if ($r['stream']) {
         if (!WP_DEBUG) {
             $stream_handle = @fopen($r['filename'], 'w+');
         } else {
             $stream_handle = fopen($r['filename'], 'w+');
         }
         if (!$stream_handle) {
             return new WP_Error('http_request_failed', sprintf(__('Could not open handle for fopen() to %s'), $r['filename']));
         }
         $bytes_written = 0;
         while (!feof($handle) && $keep_reading) {
             $block = fread($handle, $block_size);
             if (!$bodyStarted) {
开发者ID:awais300,项目名称:bds.dev,代码行数:67,代码来源:class-http.php

示例3: sixscan_common_is_fopen_working

function sixscan_common_is_fopen_working()
{
    $url = SIXSCAN_BODYGUARD_PING_URL;
    $arrContext = array('http' => array('method' => 'GET', 'user_agent' => 'SIXSCAN_SUBMITTER', 'max_redirects' => 6, 'protocol_version' => (double) '1.1', 'header' => '', 'ignore_errors' => true, 'timeout' => 30, 'ssl' => array('verify_peer' => false, 'verify_host' => false)));
    $proxy = new WP_HTTP_Proxy();
    if ($proxy->is_enabled() && $proxy->send_through_proxy($url)) {
        $arrContext['http']['proxy'] = 'tcp://' . $proxy->host() . ':' . $proxy->port();
        $arrContext['http']['request_fulluri'] = true;
        if ($proxy->use_authentication()) {
            $arrContext['http']['header'] .= $proxy->authentication_header() . "\r\n";
        }
    }
    $context = stream_context_create($arrContext);
    $handle = @fopen($url, 'r', false, $context);
    if (!$handle) {
        $last_error = error_get_last();
        $fopen_info = "failed. Last error: " . print_r($last_error, TRUE) . "\n";
        return $fopen_info;
    } else {
        fclose($handle);
        return TRUE;
    }
}
开发者ID:nhathong1204,项目名称:bdshungthinh,代码行数:23,代码来源:common.php


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