本文整理汇总了PHP中wp_remote_retrieve_headers函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_remote_retrieve_headers函数的具体用法?PHP wp_remote_retrieve_headers怎么用?PHP wp_remote_retrieve_headers使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_remote_retrieve_headers函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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 '';
}
示例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;
}
}
示例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 ),
);
}
示例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));
}
示例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;
}
示例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));
}
示例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));
}
示例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;
}
示例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;
}
示例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));
}
示例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)];
}
示例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;
}
示例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);
}
示例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;
}
}