• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP wp_remote_retrieve_headers函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中wp_remote_retrieve_headers函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_remote_retrieve_headers函数的具体用法?PHP wp_remote_retrieve_headers怎么用?PHP wp_remote_retrieve_headers使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: __construct

 public function __construct($sURL, $iTimeout = 10, $iRedirects = 5, $aHeaders = null, $sUserAgent = null, $bForceFsockOpen = false)
 {
     $this->timeout = $iTimeout;
     $this->redirects = $iRedirects;
     $this->headers = $sUserAgent;
     $this->useragent = $sUserAgent;
     $this->url = $sURL;
     // If the scheme is not http or https.
     if (!preg_match('/^http(s)?:\\/\\//i', $sURL)) {
         $this->error = '';
         $this->success = false;
         return;
     }
     // Arguments
     $aArgs = array('timeout' => $this->timeout, 'redirection' => $this->redirects, true, 'sslverify' => false);
     if (!empty($this->headers)) {
         $aArgs['headers'] = $this->headers;
     }
     if (SIMPLEPIE_USERAGENT != $this->useragent) {
         $aArgs['user-agent'] = $this->useragent;
     }
     // Request
     $res = function_exists('wp_safe_remote_request') ? wp_safe_remote_request($sURL, $aArgs) : wp_remote_get($sURL, $aArgs);
     if (is_wp_error($res)) {
         $this->error = 'WP HTTP Error: ' . $res->get_error_message();
         $this->success = false;
         return;
     }
     $this->headers = wp_remote_retrieve_headers($res);
     $this->body = wp_remote_retrieve_body($res);
     $this->status_code = wp_remote_retrieve_response_code($res);
 }
开发者ID:ashik968,项目名称:digiplot,代码行数:32,代码来源:AmazonAutoLinks_SimplePie_File.php


示例2: pmxi_get_remote_image_ext

 function pmxi_get_remote_image_ext($filePath)
 {
     $response = wp_remote_get($filePath);
     $headers = wp_remote_retrieve_headers($response);
     $content_type = !empty($headers['content-type']) ? explode('/', $headers['content-type']) : false;
     if (!empty($content_type[1])) {
         if (preg_match('%jpeg%i', $content_type[1])) {
             return 'jpeg';
         }
         if (preg_match('%jpg%i', $content_type[1])) {
             return 'jpg';
         }
         if (preg_match('%png%i', $content_type[1])) {
             return 'png';
         }
         if (preg_match('%gif%i', $content_type[1])) {
             return 'gif';
         }
         if (preg_match('%svg%i', $content_type[1])) {
             return 'svg';
         }
         return $content_type[1] == "unknown" ? "" : $content_type[1];
     }
     return '';
 }
开发者ID:estrategasdigitales,项目名称:rufiatta,代码行数:25,代码来源:functions.php


示例3: __construct

 function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false)
 {
     $this->url = $url;
     $this->timeout = $timeout;
     $this->redirects = $redirects;
     $this->headers = $headers;
     $this->useragent = $useragent;
     $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE;
     if (preg_match('/^http(s)?:\\/\\//i', $url)) {
         $args = array('timeout' => $this->timeout, 'redirection' => $this->redirects, 'reject_unsafe_urls' => true);
         if (!empty($this->headers)) {
             $args['headers'] = $this->headers;
         }
         if (SIMPLEPIE_USERAGENT != $this->useragent) {
             //Use default WP user agent unless custom has been specified
             $args['user-agent'] = $this->useragent;
         }
         $res = wp_remote_request($url, $args);
         if (is_wp_error($res)) {
             $this->error = 'WP HTTP Error: ' . $res->get_error_message();
             $this->success = false;
         } else {
             $this->headers = wp_remote_retrieve_headers($res);
             $this->body = wp_remote_retrieve_body($res);
             $this->status_code = wp_remote_retrieve_response_code($res);
         }
     } else {
         $this->error = '';
         $this->success = false;
     }
 }
开发者ID:jospintedjou,项目名称:wordpress,代码行数:31,代码来源:class-feed.php


示例4: TSpell_http_post

/**
 * Returns array with headers in $response[0] and body in $response[1]
 * Based on a function from Akismet
 */
function TSpell_http_post( $request, $host, $path, $port = 80 ) {
	$http_args = array(
		'body'                 => $request,
		'headers'              => array(
			'Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' ),
			'Host'         => $host,
			'User-Agent'   => 'AtD/0.1'
		),
		'httpversion'          => '1.0',
		'timeout'              => apply_filters( 'atd_http_post_timeout', 15 ),
	);
	$TSpell_url = "http://{$host}{$path}";
	$response = wp_remote_post( $TSpell_url, $http_args );
	$code = (int) wp_remote_retrieve_response_code( $response );

	if ( is_wp_error( $response ) ) {
		do_action( 'atd_http_post_error', 'http-error' );
		return array();
	} elseif ( 200 != $code ) {
		do_action( 'atd_http_post_error', $code );
	}

	return array(
		wp_remote_retrieve_headers( $response ),
		wp_remote_retrieve_body( $response ),
	);
}
开发者ID:hughmcguire,项目名称:pressbooks-textbook,代码行数:31,代码来源:proxy.php


示例5: AtD_http_post

/**
 * Returns array with headers in $response[0] and body in $response[1]
 * Based on a function from Akismet
 */
function AtD_http_post($request, $host, $path, $port = 80)
{
    $http_args = array('body' => $request, 'headers' => array('Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset'), 'Host' => $host, 'User-Agent' => 'AtD/0.1'), 'httpversion' => '1.0', 'timeout' => apply_filters('atd_http_post_timeout', 15));
    // Handle non-standard ports being passed in.
    if (80 !== $port && is_numeric($port) && intval($port) > 0) {
        $host .= ':' . intval($port);
    }
    // Strip any / off the begining so we can add it back and protect against SSRF
    $path = ltrim($path, '/');
    $AtD_url = set_url_scheme("http://{$host}/{$path}");
    $response = wp_remote_post($AtD_url, $http_args);
    $code = (int) wp_remote_retrieve_response_code($response);
    if (is_wp_error($response)) {
        /**
         * Fires when there is a post error to AtD.
         *
         * @since 1.2.3
         *
         * @param int|string http-error The error that AtD runs into.
         */
        do_action('atd_http_post_error', 'http-error');
        return array();
    } elseif (200 != $code) {
        /** This action is documented in modules/after-the-deadline/proxy.php */
        do_action('atd_http_post_error', $code);
    }
    return array(wp_remote_retrieve_headers($response), wp_remote_retrieve_body($response));
}
开发者ID:dtekcth,项目名称:datateknologer.se,代码行数:32,代码来源:proxy.php


示例6: __construct

 function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false)
 {
     $this->url = $url;
     $this->timeout = $timeout;
     $this->redirects = $redirects;
     $this->headers = $headers;
     $this->useragent = $useragent;
     $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE;
     global $wpdb;
     global $fwp_credentials;
     if (preg_match('/^http(s)?:\\/\\//i', $url)) {
         $args = array('timeout' => $this->timeout, 'redirection' => $this->redirects);
         if (!empty($this->headers)) {
             $args['headers'] = $this->headers;
         }
         if (SIMPLEPIE_USERAGENT != $this->useragent) {
             //Use default WP user agent unless custom has been specified
             $args['user-agent'] = $this->useragent;
         }
         // This is ugly as hell, but communicating up and down the chain
         // in any other way is difficult.
         if (!is_null($fwp_credentials)) {
             $args['authentication'] = $fwp_credentials['authentication'];
             $args['username'] = $fwp_credentials['username'];
             $args['password'] = $fwp_credentials['password'];
         } else {
             $links = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->links} WHERE link_rss = '%s'", $url));
             if ($links) {
                 $source = new SyndicatedLink($links[0]);
                 $args['authentication'] = $source->authentication_method();
                 $args['username'] = $source->username();
                 $args['password'] = $source->password();
             }
         }
         $res = wp_remote_request($url, $args);
         if (is_wp_error($res)) {
             $this->error = 'WP HTTP Error: ' . $res->get_error_message();
             $this->success = false;
         } else {
             $this->headers = wp_remote_retrieve_headers($res);
             $this->body = wp_remote_retrieve_body($res);
             $this->status_code = wp_remote_retrieve_response_code($res);
         }
     } else {
         if (!($this->body = file_get_contents($url))) {
             $this->error = 'file_get_contents could not read the file';
             $this->success = false;
         }
     }
     // SimplePie makes a strongly typed check against integers with
     // this, but WordPress puts a string in. Which causes caching
     // to break and fall on its ass when SimplePie is getting a 304,
     // but doesn't realize it because this member is "304" instead.
     $this->status_code = (int) $this->status_code;
 }
开发者ID:vinvinh315,项目名称:maintainwebsolutions.com,代码行数:55,代码来源:feedwordpress_file.class.php


示例7: test_head_request

 function test_head_request()
 {
     // this url give a direct 200 response
     $url = 'http://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
     $response = wp_remote_head($url);
     $headers = wp_remote_retrieve_headers($response);
     $this->assertInternalType('array', $headers, "Reply wasn't array.");
     $this->assertEquals('image/jpeg', $headers['content-type']);
     $this->assertEquals('40148', $headers['content-length']);
     $this->assertEquals('200', wp_remote_retrieve_response_code($response));
 }
开发者ID:boonebgorges,项目名称:wp,代码行数:11,代码来源:functions.php


示例8: test_get_redirect

 function test_get_redirect()
 {
     // this will redirect to asdftestblog1.files.wordpress.com
     $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
     $response = wp_remote_get($url);
     $headers = wp_remote_retrieve_headers($response);
     // should return the same headers as a head request
     $this->assertEquals('image/jpeg', $headers['content-type']);
     $this->assertEquals('40148', $headers['content-length']);
     $this->assertEquals('200', wp_remote_retrieve_response_code($response));
 }
开发者ID:aaemnnosttv,项目名称:develop.git.wordpress.org,代码行数:11,代码来源:functions.php


示例9: makeRequest

 /**
  * Execute a apiHttpRequest
  *
  * @param Yoast_Google_HttpRequest $request the http request to be executed
  *
  * @return Yoast_Google_HttpRequest http request with the response http code, response
  * headers and response body filled in
  */
 public function makeRequest(Yoast_Google_HttpRequest $request)
 {
     // First, check to see if we have a valid cached version.
     $cached = $this->getCachedRequest($request);
     if ($cached !== false) {
         if (!$this->checkMustRevaliadateCachedRequest($cached, $request)) {
             return $cached;
         }
     }
     if (array_key_exists($request->getRequestMethod(), self::$ENTITY_HTTP_METHODS)) {
         $request = $this->processEntityRequest($request);
     }
     $params = array('user-agent' => $request->getUserAgent(), 'timeout' => 30, 'sslverify' => false);
     $curl_version = $this->get_curl_version();
     if ($curl_version !== false) {
         if (version_compare($curl_version, '7.19.0', '<=') && version_compare($curl_version, '7.19.8', '>')) {
             add_filter('http_api_transports', array($this, 'filter_curl_from_transports'));
         }
     }
     if ($request->getPostBody()) {
         $params['body'] = $request->getPostBody();
     }
     $requestHeaders = $request->getRequestHeaders();
     if ($requestHeaders && is_array($requestHeaders)) {
         $params['headers'] = $requestHeaders;
     }
     switch ($request->getRequestMethod()) {
         case 'POST':
             $response = wp_remote_post($request->getUrl(), $params);
             break;
         case 'GET':
             $response = wp_remote_get($request->getUrl(), $params);
             break;
     }
     $responseBody = wp_remote_retrieve_body($response);
     $respHttpCode = wp_remote_retrieve_response_code($response);
     $responseHeaders = wp_remote_retrieve_headers($response);
     if ($respHttpCode == 304 && $cached) {
         // If the server responded NOT_MODIFIED, return the cached request.
         $this->updateCachedRequest($cached, $responseHeaders);
         return $cached;
     }
     // Fill in the apiHttpRequest with the response values
     $request->setResponseHttpCode($respHttpCode);
     $request->setResponseHeaders($responseHeaders);
     $request->setResponseBody($responseBody);
     // Store the request in cache (the function checks to see if the request
     // can actually be cached)
     $this->setCachedRequest($request);
     // And finally return it
     return $request;
 }
开发者ID:santikrass,项目名称:apache,代码行数:60,代码来源:Google_WPIO.php


示例10: wc_rest_upload_image_from_url

/**
 * Upload image from URL.
 *
 * @since 2.6.0
 * @param string $image_url
 * @return array|WP_Error Attachment data or error message.
 */
function wc_rest_upload_image_from_url($image_url)
{
    $file_name = basename(current(explode('?', $image_url)));
    $parsed_url = @parse_url($image_url);
    // Check parsed URL.
    if (!$parsed_url || !is_array($parsed_url)) {
        return new WP_Error('woocommerce_rest_invalid_image_url', sprintf(__('Invalid URL %s.', 'woocommerce'), $image_url), array('status' => 400));
    }
    // Ensure url is valid.
    $image_url = esc_url_raw($image_url);
    // Get the file.
    $response = wp_safe_remote_get($image_url, array('timeout' => 10));
    if (is_wp_error($response)) {
        return new WP_Error('woocommerce_rest_invalid_remote_image_url', sprintf(__('Error getting remote image %s.', 'woocommerce'), $image_url) . ' ' . sprintf(__('Error: %s.', 'woocommerce'), $response->get_error_message()), array('status' => 400));
    } elseif (200 !== wp_remote_retrieve_response_code($response)) {
        return new WP_Error('woocommerce_rest_invalid_remote_image_url', sprintf(__('Error getting remote image %s.', 'woocommerce'), $image_url), array('status' => 400));
    }
    // Ensure we have a file name and type.
    $wp_filetype = wp_check_filetype($file_name, wc_rest_allowed_image_mime_types());
    if (!$wp_filetype['type']) {
        $headers = wp_remote_retrieve_headers($response);
        if (isset($headers['content-disposition']) && strstr($headers['content-disposition'], 'filename=')) {
            $disposition = end(explode('filename=', $headers['content-disposition']));
            $disposition = sanitize_file_name($disposition);
            $file_name = $disposition;
        } elseif (isset($headers['content-type']) && strstr($headers['content-type'], 'image/')) {
            $file_name = 'image.' . str_replace('image/', '', $headers['content-type']);
        }
        unset($headers);
        // Recheck filetype
        $wp_filetype = wp_check_filetype($file_name, wc_rest_allowed_image_mime_types());
        if (!$wp_filetype['type']) {
            return new WP_Error('woocommerce_rest_invalid_image_type', __('Invalid image type.', 'woocommerce'), array('status' => 400));
        }
    }
    // Upload the file.
    $upload = wp_upload_bits($file_name, '', wp_remote_retrieve_body($response));
    if ($upload['error']) {
        return new WP_Error('woocommerce_rest_image_upload_error', $upload['error'], array('status' => 400));
    }
    // Get filesize.
    $filesize = filesize($upload['file']);
    if (0 == $filesize) {
        @unlink($upload['file']);
        unset($upload);
        return new WP_Error('woocommerce_rest_image_upload_file_error', __('Zero size file downloaded.', 'woocommerce'), array('status' => 400));
    }
    do_action('woocommerce_rest_api_uploaded_image_from_url', $upload, $image_url);
    return $upload;
}
开发者ID:tlovett1,项目名称:woocommerce,代码行数:57,代码来源:wc-rest-functions.php


示例11: AtD_http_post

/**
 * Returns array with headers in $response[0] and body in $response[1]
 * Based on a function from Akismet
 */
function AtD_http_post($request, $host, $path, $port = 80)
{
    $http_args = array('body' => $request, 'headers' => array('Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset'), 'Host' => $host, 'User-Agent' => 'AtD/0.1'), 'httpversion' => '1.0', 'timeout' => apply_filters('atd_http_post_timeout', 15));
    // Strip any / off the begining so we can add it back and protect against SSRF
    $path = ltrim($path, '/');
    $AtD_url = "http://{$host}/{$path}";
    $response = wp_remote_post($AtD_url, $http_args);
    $code = (int) wp_remote_retrieve_response_code($response);
    if (is_wp_error($response)) {
        do_action('atd_http_post_error', 'http-error');
        return array();
    } elseif (200 != $code) {
        do_action('atd_http_post_error', $code);
    }
    return array(wp_remote_retrieve_headers($response), wp_remote_retrieve_body($response));
}
开发者ID:aim-web-projects,项目名称:kobe-chuoh,代码行数:20,代码来源:proxy.php


示例12: get

 /**
  * Send a GET request to the given endpoint.
  *
  * @param  string $endpoint Appended to $url_root to create the URL.
  *
  * @return array
  *
  * @throws \InvalidArgumentException When endpoint is not a string.
  * @throws \RuntimeException When $response is a WP_Error.
  */
 public function get($endpoint)
 {
     if (!is_string($endpoint)) {
         throw new \InvalidArgumentException(sprintf('The endpoint parameter is required to be string, was: %s', gettype($endpoint)));
     }
     $endpoint = ltrim($endpoint, '/\\');
     $url = sprintf('https://wpvulndb.com/api/v2/%s', $endpoint);
     $name = 'Soter Security Checker';
     $version = '0.3.0';
     $soter_url = 'https://github.com/ssnepenthe/soter';
     $args = ['user-agent' => sprintf('%s | v%s | %s', $name, $version, $soter_url)];
     $response = wp_safe_remote_get($url, $args);
     if (is_wp_error($response)) {
         throw new \RuntimeException(sprintf('WP Error: %s', $response->get_error_message()));
     }
     return [wp_remote_retrieve_response_code($response), wp_remote_retrieve_headers($response), wp_remote_retrieve_body($response)];
 }
开发者ID:ssnepenthe,项目名称:soter,代码行数:27,代码来源:WPClient.php


示例13: execute

 /**
  * @param $selected_call
  * @param $method_type
  * @param $params
  * @return string
  * @throws W3tcWpHttpException
  */
 private function execute($selected_call, $method_type, $params)
 {
     //increase the http request timeout
     add_filter('http_request_timeout', array($this, 'filter_timeout_time'));
     $consumer = new W3tcOAuthConsumer($this->key, $this->secret, NULL);
     // the endpoint for your request
     $endpoint = "{$this->netdnarws_url}/{$this->alias}{$selected_call}";
     //parse endpoint before creating OAuth request
     $parsed = parse_url($endpoint);
     if (array_key_exists("parsed", $parsed)) {
         parse_str($parsed['query'], $params);
     }
     //generate a request from your consumer
     $req_req = W3tcOAuthRequest::from_consumer_and_token($consumer, NULL, $method_type, $endpoint, $params);
     //sign your OAuth request using hmac_sha1
     $sig_method = new W3tcOAuthSignatureMethod_HMAC_SHA1();
     $req_req->sign_request($sig_method, $consumer, NULL);
     $headers = $request = array();
     $request['sslverify'] = false;
     $request['method'] = $method_type;
     if ($method_type == "POST" || $method_type == "PUT" || $method_type == "DELETE") {
         $request['body'] = $params;
     }
     $response = wp_remote_request($req_req, $request);
     $json_output = '';
     if (!is_wp_error($response)) {
         // make call
         $result = wp_remote_retrieve_body($response);
         $headers = wp_remote_retrieve_headers($response);
         $response_code = wp_remote_retrieve_response_code($response);
         // $json_output contains the output string
         $json_output = $result;
     } else {
         $response_code = $response->get_error_code();
     }
     remove_filter('http_request_timeout', array($this, 'filter_timeout_time'));
     // catch errors
     if (is_wp_error($response)) {
         throw new W3tcWpHttpException("ERROR: {$response->get_error_message()}, Output: {$json_output}", $response_code, null, $headers);
     }
     return $json_output;
 }
开发者ID:jfbelisle,项目名称:magexpress,代码行数:49,代码来源:NetDNA.php


示例14: powerpress_admin_verify_url

function powerpress_admin_verify_url($url)
{
    $response = wp_remote_head($url, array('httpversion' => 1.1));
    for ($x = 0; $x < 5; $x++) {
        // Redirect 1-5
        if (!is_wp_error($response) && ($response['response']['code'] == 301 || $response['response']['code'] == 302)) {
            $headers = wp_remote_retrieve_headers($response);
            $response = wp_remote_head($headers['location'], array('httpversion' => 1.1));
        } else {
            break;
            // Either we had an error or the response code is no longer a redirect
        }
    }
    if (is_wp_error($response)) {
        return array('error' => $response->get_error_message());
    }
    if (isset($response['response']['code']) && ($response['response']['code'] < 200 || $response['response']['code'] > 203)) {
        return array('error' => 'Error, HTTP ' . $response['response']['code']);
    }
    return array('error' => false);
}
开发者ID:ajay786singh,项目名称:emc,代码行数:21,代码来源:powerpressadmin-migrate.php


示例15: remote

 public static function remote($url = FALSE, $post_vars = FALSE, $args = FALSE, $return = FALSE)
 {
     if ($url && is_string($url)) {
         $args = !is_array($args) ? array() : $args;
         /* Force array, and disable SSL verification. */
         $args["sslverify"] = !isset($args["sslverify"]) ? false : $args["sslverify"];
         /**/
         if ((is_array($post_vars) || is_string($post_vars)) && !empty($post_vars)) {
             $args = array_merge($args, array("method" => "POST", "body" => $post_vars));
         }
         /**/
         $response = wp_remote_request($url, $args);
         /* Process the remote request now. */
         /**/
         if (strcasecmp((string) $return, "array") === 0 && !is_wp_error($response) && is_array($response)) {
             $a = array("code" => (int) wp_remote_retrieve_response_code($response));
             $a = array_merge($a, array("message" => wp_remote_retrieve_response_message($response)));
             $a = array_merge($a, array("headers" => wp_remote_retrieve_headers($response)));
             $a = array_merge($a, array("body" => wp_remote_retrieve_body($response)));
             $a = array_merge($a, array("response" => $response));
             /**/
             return $a;
         } else {
             if (!is_wp_error($response) && is_array($response)) {
                 return wp_remote_retrieve_body($response);
             } else {
                 /* Else this remote request has failed completely. Return false. */
                 return false;
             }
         }
         /* Remote request failed, return false. */
     } else {
         /* Else, return false. */
         return false;
     }
 }
开发者ID:arturo-mayorga,项目名称:am_com,代码行数:36,代码来源:utils-urls.inc.php


示例16: powerpress_admin_verify_url

function powerpress_admin_verify_url($url)
{
    $wp_remote_options = array();
    $wp_remote_options['user-agent'] = 'Blubrry PowerPress/' . POWERPRESS_VERSION;
    $wp_remote_options['httpversion'] = '1.1';
    $response = wp_remote_head($url, $wp_remote_options);
    for ($x = 0; $x < 5; $x++) {
        // Redirect 1-5
        if (!is_wp_error($response) && ($response['response']['code'] == 301 || $response['response']['code'] == 302)) {
            $headers = wp_remote_retrieve_headers($response);
            $response = wp_remote_head($headers['location'], $wp_remote_options);
        } else {
            break;
            // Either we had an error or the response code is no longer a redirect
        }
    }
    if (is_wp_error($response)) {
        return array('error' => $response->get_error_message());
    }
    if (isset($response['response']['code']) && ($response['response']['code'] < 200 || $response['response']['code'] > 203)) {
        return array('error' => 'Error, HTTP ' . $response['response']['code']);
    }
    return array('error' => false);
}
开发者ID:mattsims,项目名称:powerpress,代码行数:24,代码来源:powerpressadmin-migrate.php


示例17: _fetch_remote_file

/**
 * Retrieve URL headers and content using WP HTTP Request API.
 *
 * @since 1.5.0
 * @package External
 * @subpackage MagpieRSS
 *
 * @param string $url URL to retrieve
 * @param array $headers Optional. Headers to send to the URL.
 * @return Snoopy style response
 */
function _fetch_remote_file($url, $headers = "")
{
    $resp = wp_safe_remote_request($url, array('headers' => $headers, 'timeout' => MAGPIE_FETCH_TIME_OUT));
    if (is_wp_error($resp)) {
        $error = array_shift($resp->errors);
        $resp = new stdClass();
        $resp->status = 500;
        $resp->response_code = 500;
        $resp->error = $error[0] . "\n";
        //\n = Snoopy compatibility
        return $resp;
    }
    // Snoopy returns headers unprocessed.
    // Also note, WP_HTTP lowercases all keys, Snoopy did not.
    $return_headers = array();
    foreach (wp_remote_retrieve_headers($resp) as $key => $value) {
        if (!is_array($value)) {
            $return_headers[] = "{$key}: {$value}";
        } else {
            foreach ($value as $v) {
                $return_headers[] = "{$key}: {$v}";
            }
        }
    }
    $response = new stdClass();
    $response->status = wp_remote_retrieve_response_code($resp);
    $response->response_code = wp_remote_retrieve_response_code($resp);
    $response->headers = $return_headers;
    $response->results = wp_remote_retrieve_body($resp);
    return $response;
}
开发者ID:ajspencer,项目名称:NCSSM-SG-WordPress,代码行数:42,代码来源:rss.php


示例18: handle_response

 /**
  * Handle and parse the response
  *
  * @since 2.2.0
  * @param array|WP_Error $response response data
  * @throws \SV_WC_API_Exception network issues, timeouts, API errors, etc
  * @return object request class instance that implements SV_WC_API_Request
  */
 protected function handle_response($response)
 {
     // check for WP HTTP API specific errors (network timeout, etc)
     if (is_wp_error($response)) {
         throw new SV_WC_API_Exception($response->get_error_message(), (int) $response->get_error_code());
     }
     // set response data
     $this->response_code = wp_remote_retrieve_response_code($response);
     $this->response_message = wp_remote_retrieve_response_message($response);
     $this->response_headers = wp_remote_retrieve_headers($response);
     $this->raw_response_body = wp_remote_retrieve_body($response);
     // allow child classes to validate response prior to parsing -- this is useful
     // for checking HTTP status codes, etc.
     $this->do_pre_parse_response_validation();
     // parse the response body and tie it to the request
     $this->response = $this->get_parsed_response($this->raw_response_body);
     // allow child classes to validate response after parsing -- this is useful
     // for checking error codes/messages included in a parsed response
     $this->do_post_parse_response_validation();
     // fire do_action() so other actors can act on request/response data,
     // primarily used for logging
     $this->broadcast_request();
     return $this->response;
 }
开发者ID:javolero,项目名称:dabba,代码行数:32,代码来源:class-sv-wc-api-base.php


示例19: __construct

	function __construct ($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false) {
		global $feedwordpress;
		global $wp_version;

		$source = NULL;
		if ($feedwordpress->subscribed($url)) :
			$source = $feedwordpress->subscription($url);
		endif;
		
		$this->url = $url;
		$this->timeout = $timeout;
		$this->redirects = $redirects;
		$this->headers = $headers;
		$this->useragent = $useragent;

		$this->method = SIMPLEPIE_FILE_SOURCE_REMOTE;
		
		global $wpdb;
		global $fwp_credentials;
		
		if ( preg_match('/^http(s)?:\/\//i', $url) ) {
			$args = array( 'timeout' => $this->timeout, 'redirection' => $this->redirects);
	
			if ( !empty($this->headers) )
				$args['headers'] = $this->headers;

			// Use default FWP user agent unless custom has been specified
			if ( SIMPLEPIE_USERAGENT != $this->useragent ) :
				$args['user-agent'] = $this->useragent;
			else :
				$args['user-agent'] = apply_filters('feedwordpress_user_agent',
					'FeedWordPress/'.FEEDWORDPRESS_VERSION
					.' (aggregator:feedwordpress; WordPress/'.$wp_version
					.' + '.SIMPLEPIE_NAME.'/'.SIMPLEPIE_VERSION
					.'; Allow like Gecko; +http://feedwordpress.radgeek.com/) at '
					. feedwordpress_display_url(get_bloginfo('url')),
					$this
				);
			endif;

			// This is ugly as hell, but communicating up and down the chain
			// in any other way is difficult.

			if (!is_null($fwp_credentials)) :

				$args['authentication'] = $fwp_credentials['authentication'];
				$args['username'] = $fwp_credentials['username'];
				$args['password'] = $fwp_credentials['password'];

			elseif ($source InstanceOf SyndicatedLink) :

				$args['authentication'] = $source->authentication_method();
				$args['username'] = $source->username();
				$args['password'] = $source->password();
			
			endif;

			FeedWordPress::diagnostic('updated_feeds:http', "HTTP [$url] &#8668; ".esc_html(FeedWordPress::val($args)));
			$res = wp_remote_request($url, $args);
			FeedWordPress::diagnostic('updated_feeds:http', "HTTP [$url] &#8669; ".esc_html(FeedWordPress::val($res)));

			if ( is_wp_error($res) ) {
				$this->error = 'WP HTTP Error: ' . $res->get_error_message();
				$this->success = false;
			} else {
				$this->headers = wp_remote_retrieve_headers( $res );
				$this->body = wp_remote_retrieve_body( $res );
				$this->status_code = wp_remote_retrieve_response_code( $res );
			}
			
			if ($source InstanceOf SyndicatedLink) :
				$source->update_setting('link/filesize', strlen($this->body));
				$source->update_setting('link/http status', $this->status_code);
				$source->save_settings(/*reload=*/ true);
			endif;
			
		} else {
			if ( ! $this->body = file_get_contents($url) ) {
				$this->error = 'file_get_contents could not read the file';
				$this->success = false;
			}
		}

		// SimplePie makes a strongly typed check against integers with
		// this, but WordPress puts a string in. Which causes caching
		// to break and fall on its ass when SimplePie is getting a 304,
		// but doesn't realize it because this member is "304" instead.
		$this->status_code = (int) $this->status_code;
	}
开发者ID:kevinreilly,项目名称:mendelements.com,代码行数:89,代码来源:feedwordpress_file.class.php


示例20: wp_get_http_headers

/**
 * Retrieve HTTP Headers from URL.
 *
 * @since 1.5.1
 *
 * @param string $url
 * @param bool $deprecated Not Used.
 * @return bool|string False on failure, headers on success.
 */
function wp_get_http_headers($url, $deprecated = false)
{
    $response = wp_remote_head($url);
    if (is_wp_error($response)) {
        return false;
    }
    return wp_remote_retrieve_headers($response);
}
开发者ID:joelglennwright,项目名称:agencypress,代码行数:17,代码来源:functions.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP wp_remote_retrieve_response_code函数代码示例发布时间:2022-05-23
下一篇:
PHP wp_remote_retrieve_header函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap