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


PHP WP_Http::request方法代码示例

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


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

示例1: is_valid

 /**
  * Makes a http request to the url this points at and checks if the requests
  * returns the correct validation result.
  *
  * @return bool
  */
 public function is_valid()
 {
     $url_glue = false === strpos($this->url, '?') ? '?' : '&';
     $url = trailingslashit($this->url) . ($this->language_code ? '/' . $this->language_code . '/' : '') . $url_glue . '____icl_validate_domain=1';
     $response = $this->http->request($url, 'timeout=15');
     return !is_wp_error($response) && $response['response']['code'] == '200' && ($response['body'] === '<!--' . untrailingslashit($this->wp_api->get_home_url()) . '-->' || $response['body'] === '<!--' . untrailingslashit($this->wp_api->get_site_url()) . '-->');
 }
开发者ID:SayenkoDesign,项目名称:ividf,代码行数:13,代码来源:class-wpml-language-domain-validation.php

示例2: embed_github_gist

/**
 * Gets content from GitHub Gist
 * 
 * @param int $id GitHub Gist ID
 * @param int $ttl How long to cache (in seconds)
 * @param string $bump Bump value to force cache expirey.
 * @param string $file Name of file
 */
function embed_github_gist($id, $ttl = null, $bump = null, $file = null)
{
    $gist = '';
    if (!class_exists('WP_Http')) {
        require_once ABSPATH . WPINC . '/class-http.php';
    }
    $key = embed_github_gist_build_cache_key($id, $bump);
    if (embed_github_gist_bypass_cache() or false === ($gist = get_transient($key))) {
        $http = new WP_Http();
        if (embed_github_gist_prefer_inline_html() and function_exists('json_decode')) {
            $result = $http->request('https://gist.github.com/' . $id . '.json');
            $json = json_decode($result['body']);
            $gist = $json->div;
        } else {
            if (!$file) {
                $file = 'file';
            }
            $result = $http->request('https://gist.github.com/raw/' . $id . '/' . $file);
            $gist = '<script src="https://gist.github.com/' . $id . '.js?file=' . $file . '%5B345%5D" type="text/javascript"></script>';
            $gist .= '<noscript><div class="embed-github-gist-source"><code><pre>';
            $gist .= htmlentities($result['body']);
            $gist .= '</pre></code></div></noscript>';
        }
        unset($result, $http);
        if (!embed_github_gist_bypass_cache()) {
            if (!$ttl) {
                $ttl = EMBED_GISTHUB_DEFAULT_TTL;
            }
            set_transient($key, $gist, $ttl);
        }
    }
    return $gist;
}
开发者ID:rud,项目名称:embed-github-gist,代码行数:41,代码来源:embed-github-gist.php

示例3: call_remote_api

 /**
  * @param string $url
  * @param array  $params
  * @param string $method
  * @param bool   $has_return_value
  *
  * @throws RuntimeException
  *
  * @return null|string
  */
 private function call_remote_api($url, $params, $method, $has_return_value = true)
 {
     $context = $this->filter_request_params($params, $method);
     $response = $this->http->request($url, $context);
     if ($has_return_value && (bool) $response === false || is_wp_error($response) || isset($response['response']['code']) && $response['response']['code'] > 400) {
         throw new RuntimeException("Cannot communicate with the remote service params: " . serialize($context) . ' response: ' . serialize($response));
     }
     return $response;
 }
开发者ID:agiper,项目名称:wordpress,代码行数:19,代码来源:class-wpml-translation-proxy-networking.php

示例4: socialdiscuss_http_post

function socialdiscuss_http_post($link, $body)
{
    if (!$link) {
        return array(500, 'Invalid Link');
    }
    require_once ABSPATH . WPINC . '/class-snoopy.php';
    $snoop = new Snoopy();
    if ($snoop->submit($link, $body)) {
        if (strpos($snoop->response_code, '200')) {
            $response = $snoop->results;
            return array(200, $response);
        }
    }
    if (!class_exists('WP_Http')) {
        include_once ABSPATH . WPINC . '/class-http.php';
    }
    if (!class_exists('WP_Http')) {
        return array(500, $snoop->response_code);
    }
    $request = new WP_Http();
    $response_full = $request->request($link, array('method' => 'POST', 'body' => $body, 'headers' => $headers));
    if (isset($response_full->errors)) {
        return array(500, 'Unknown Error');
    }
    $response_code = $response_full['response']['code'];
    if ($response_code === 200) {
        $response = $response_full['body'];
        return array($response_code, $response);
    }
    $response_msg = $response_full['response']['message'];
    return array($response_code, $response_msg);
}
开发者ID:hypenotic,项目名称:slowfood,代码行数:32,代码来源:social-discussions-utility-fns.php

示例5: elseif

 function jws_fetchUrl($url)
 {
     //Can we use cURL?
     if (is_callable('curl_init')) {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_TIMEOUT, 20);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         $feedData = curl_exec($ch);
         curl_close($ch);
         //If not then use file_get_contents
     } elseif (ini_get('allow_url_fopen') == 1 || ini_get('allow_url_fopen') === TRUE) {
         $feedData = @file_get_contents($url);
         //Or else use the WP HTTP API
     } else {
         if (!class_exists('WP_Http')) {
             include_once ABSPATH . WPINC . '/class-http.php';
         }
         $request = new WP_Http();
         $result = $request->request($url);
         $feedData = $result['body'];
     }
     /*    echo $feedData;
     		exit;*/
     return $feedData;
 }
开发者ID:ICONVI,项目名称:sigmacatweb,代码行数:27,代码来源:core-functions.php

示例6: sendRequest

 /**
  * @param string $path
  * @param string $method
  * @param array $data
  * @param string $contentType
  *
  * @return array
  * @throws CommunicationError
  * @throws Exception\InvalidResponseError
  * @throws Exception\LaunchKeyEngineError
  * @throws Exception\NoPairedDevicesError
  * @throws Exception\NoSuchUserError
  * @throws Exception\RateLimitExceededError
  * @throws ExpiredAuthRequestError
  * @throws InvalidCredentialsError
  * @throws InvalidRequestError
  */
 private function sendRequest($path, $method, array $data = array(), array $parameters = array(), $contentType = 'application/x-www-form-urlencoded')
 {
     $headers = array('Accept' => 'application/json', 'Connection' => 'close');
     if (!empty($data)) {
         $headers['Content-Type'] = $contentType;
         if ($contentType === 'application/x-www-form-urlencoded') {
             $body = http_build_query($data);
         } elseif ($contentType === 'application/json') {
             $body = json_encode($data);
             $parameters['signature'] = $this->cryptService->sign($body);
         }
     } else {
         $body = null;
     }
     if (!empty($parameters)) {
         $path .= '?' . http_build_query($parameters);
     }
     $this->debugLog("Sending request", array('path' => $path, 'method' => $method, 'headers' => $headers, 'body' => $body));
     $response = $this->http->request($this->getUrl($path), array('method' => $method, 'timeout' => $this->requestTimeout, 'redirection' => 0, 'httpversion' => '1.1', 'sslverify' => $this->sslVerify, 'body' => $body, 'headers' => $headers));
     if ($response instanceof \WP_Error) {
         $msg = implode(' => ', $response->get_error_messages());
         throw new CommunicationError($msg);
     } else {
         $this->debugLog("Response received", array($response));
         $data = $this->jsonDecodeData($response['body']);
         if (!in_array($response['response']['code'], array(200, 201))) {
             $this->throwExceptionForErrorResponse($data);
         }
     }
     return $data;
 }
开发者ID:ThemeSurgeon,项目名称:launchkey-php,代码行数:48,代码来源:WordPressApiService.php

示例7: kpg_read_file

function kpg_read_file($f, $method = 'GET')
{
    // try this using Wp_Http
    if (!class_exists('WP_Http')) {
        include_once ABSPATH . WPINC . '/class-http.php';
    }
    $request = new WP_Http();
    $parms = array();
    $parms['timeout'] = 10;
    // bump timeout a little we are timing out in google
    $parms['method'] = $method;
    $result = $request->request($f, $parms);
    // see if there is anything there
    if (empty($result)) {
        return '';
    }
    if (is_array($result)) {
        $ansa = $result['body'];
        return $ansa;
    }
    if (is_object($result)) {
        $ansa = 'ERR: ' . $result->get_error_message();
        return $ansa;
        // return $ansa when debugging
        //return '';
    }
    return '';
}
开发者ID:healthcommcore,项目名称:osnap,代码行数:28,代码来源:stop-spam-utils.php

示例8: prli_get_main_message

function prli_get_main_message($message = '', $expiration = 1800)
{
    global $prli_update;
    // Set the default message
    if (empty($message)) {
        $message = __("Get started by <a href=\"?page=pretty-link&action=new\">" . "adding a URL</a> that you want to turn into a pretty link.<br/>" . "Come back to see how many times it was clicked.", 'pretty-link');
    }
    $messages = get_site_transient('_prli_messages');
    // if the messages array has expired go back to the mothership
    if (!$messages) {
        $remote_controller = $prli_update->pro_is_installed_and_authorized() ? 'prlipro' : 'prli';
        $message_mothership = "http://prettylinkpro.com/index.php?controller={$remote_controller}&action=json_messages";
        if (!class_exists('WP_Http')) {
            include_once ABSPATH . WPINC . '/class-http.php';
        }
        $http = new WP_Http();
        $response = $http->request($message_mothership);
        if (isset($response) and is_array($response) and isset($response['body']) and !empty($response['body'])) {
            $messages = json_decode($response['body']);
        } else {
            $messages = array($message);
        }
        set_site_transient("_prli_messages", $messages, $expiration);
    }
    if (empty($messages) or !$messages or !is_array($messages)) {
        return $message;
    } else {
        return $messages[array_rand($messages)];
    }
}
开发者ID:phpwomen,项目名称:combell,代码行数:30,代码来源:models.inc.php

示例9: array

 function do_request($url, $oauth_header, $body_params = '')
 {
     $request = new WP_Http();
     $params = array();
     if ($body_params) {
         foreach ($body_params as $key => $value) {
             $body_params[$key] = $value;
         }
         $params['body'] = $body_params;
     }
     $params['method'] = 'POST';
     $params['headers'] = array('Authorization' => $oauth_header);
     $result = $request->request($url, $params);
     if (!is_wp_error($result)) {
         $this->response_code = $result['response']['code'];
         if ($result['response']['code'] == '200') {
             return $result['body'];
         } else {
             switch ($result['response']['code']) {
                 case 403:
                     $this->duplicate_tweet = true;
                     break;
             }
             $error_message_found = preg_match('#<error>(.*)</error>#i', $result['body'], $matches);
             if ($error_message_found) {
                 $this->error_message = $matches[1];
             }
         }
     }
     return false;
 }
开发者ID:MediehusetNettavisenAS,项目名称:wp-blogsoft,代码行数:31,代码来源:oauth-blogsoft.php

示例10: genesis_purchase_themes_admin

function genesis_purchase_themes_admin()
{
    ?>
	
<div class="wrap purchase-themes">
	<?php 
    screen_icon('themes');
    ?>
	<h2><?php 
    echo 'Genesis ';
    _e('- Purchase Themes', 'genesis');
    ?>
</h2>
	
	<?php 
    $store = get_transient('genesis-remote-store');
    if (!$store) {
        $request = new WP_Http();
        $store = $request->request('http://www.studiopress.com/store.php');
        set_transient('genesis-remote-store', $store, 60 * 60 * 12);
        // store for 12 hours
    }
    echo $store['body'];
    ?>
	
</div>
<?php 
}
开发者ID:Weissenberger13,项目名称:web.portugalrentalcottages,代码行数:28,代码来源:purchase_themes.php

示例11: request

 /**
  * Send an authenticated request to the Urban Airship API. The request is
  * authenticated with the key and secret.
  *
  * @param string  $method      REST method for request
  * @param mixed   $body        Body of request, optional
  * @param string  $uri         URI for this request
  * @param string  $contentType Content type for the request, optional
  * @param int     $version     version # for API, optional, default is 3
  * @param mixed   $request     Request object for this operation (PushRequest, etc)
  *   optional
  * @return \Httpful\associative|string
  * @throws AirshipException
  */
 public function request($method, $body, $uri, $contentType = null, $version = 3, $request = null)
 {
     // As a result of replacing Httpful/Request with WP HTTP,
     // We need to map WP_HTTP response object to Httpful/Request properties as a shim,
     // Action is not necessary but looks a bit cleaner
     add_action('http_api_debug', array($this, 'set_mock_response_object'), 10, 5);
     $headers = array('Authorization' => 'Basic ' . base64_encode("{$this->key}:{$this->secret}"), "Accept" => sprintf(self::VERSION_STRING, $version));
     if (!is_null($contentType)) {
         $headers["Content-type"] = $contentType;
     }
     $request = new \WP_Http();
     /**
      * Logger is disabled in production, so this won't do nothing unless WP_DEBUG is enabled
      *
      * @var [type]
      */
     $logger = UALog::getLogger();
     $logger->debug("Making request", array("method" => $method, "uri" => $uri, "headers" => $headers, "body" => $body));
     // Make a request (fires http_api_debug action that sets object property $mock_response)
     $response = $request->request($uri, array('method' => $method, 'body' => $body, 'headers' => $headers));
     // Check the response for wp_error (that's what WP HTTP throws when there was an issue with request)
     if (is_wp_error($response)) {
         return $response;
     }
     // Check for "successful" WP HTTP request and see if UA returns any non-2xx response code
     if (300 <= $response['response']['code']) {
         throw AirshipException::fromResponse($this->mock_response);
     }
     $logger->debug("Received response", array("status" => $this->mock_response->code, "headers" => $this->mock_response->raw_headers, "body" => $this->mock_response->raw_body));
     // Return mock response object for any components of UA library that make requests
     return $this->mock_response;
 }
开发者ID:gopinathshiva,项目名称:wordpress-vip-plugins,代码行数:46,代码来源:class.wpairship.php

示例12: cff_fetchUrl

function cff_fetchUrl($url)
{
    //Can we use cURL?
    if (is_callable('curl_init')) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 20);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate,sdch');
        $feedData = curl_exec($ch);
        curl_close($ch);
        //If not then use file_get_contents
    } elseif (ini_get('allow_url_fopen') == 1 || ini_get('allow_url_fopen') === TRUE) {
        $feedData = @file_get_contents($url);
        //Or else use the WP HTTP API
    } else {
        $request = new WP_Http();
        $response = $request->request($urls, array('timeout' => 60, 'sslverify' => false));
        if (is_wp_error($response)) {
            //Don't display an error, just use the Server config Error Reference message
            echo '';
        } else {
            $feedData = wp_remote_retrieve_body($response);
        }
    }
    return $feedData;
}
开发者ID:treydonovan,项目名称:innergame-anna,代码行数:28,代码来源:connect.php

示例13: rest_api_call

 /**
  * Method responsible for making Rest API calls @ Return $response from rest api.
  *
  * @return $response
  */
 public function rest_api_call()
 {
     try {
         if (!class_exists('WP_Http')) {
             include_once ABSPATH . WPINC . '/class-http.php';
         }
         $request = new WP_Http();
         $postfields = $this->getPostfields();
         $header = $this->getHeaders();
         $url = $this->getApiUrl();
         $options = array('headers' => $header, 'method' => $this->method, 'timeout' => ConfigSDK::TIMEOUT);
         if (!is_null($postfields)) {
             $options['body'] = $postfields;
         }
         //SSL PROBLEMS
         $options['sslverify'] = false;
         $result = $request->request($url, $options);
         if (!is_wp_error($result)) {
             $json = $result['body'];
             $response = json_decode($json, true);
             $response_status = $result['response']['code'];
             $this->setLastStatusCode($response_status);
         } else {
             $this->setLastStatusCode(0);
         }
         if ($this->authorization->is_preauthorized_request) {
             $this->authorization->setAccessParams($response);
         }
         return $response;
     } catch (Exception $e) {
         throw new Exception('Failed to send Data in rest_api_call: ' . $e);
     }
 }
开发者ID:acasado86,项目名称:sdk-php,代码行数:38,代码来源:WP_NimbleAPI.php

示例14: load_ipn_ips

 /**
  * Load IPN IP List
  * @since 1.1
  * @version 1.0
  */
 public function load_ipn_ips()
 {
     $request = new WP_Http();
     $data = $request->request('http://www.zombaio.com/ip_list.txt');
     $data = explode('|', $data['body']);
     return $data;
 }
开发者ID:socialray,项目名称:surfied-2-0,代码行数:12,代码来源:zombaio.php

示例15: ml_send_notification

function ml_send_notification($alert, $sound = true, $badge = NULL, $custom_properties = NULL, $tags = NULL, $remote_identifier = NULL)
{
    global $ml_api_key, $ml_secret_key;
    //push notification only when api key is set
    if (($ml_api_key == NULL || strlen($ml_api_key) < 5) && ($ml_secret_key == NULL || strlen($ml_secret_key) < 5)) {
        return false;
    }
    $notification = array('alert' => $alert);
    if ($sound) {
        $notification['sound'] = $sound;
    }
    if ($badge) {
        $notification['badge'] = $badge;
    }
    if ($custom_properties) {
        $notification['custom_properties'] = $custom_properties;
    }
    if ($tags) {
        $notification['tags'] = $tags;
    }
    $parameters = array('api_key' => $ml_api_key, 'secret_key' => $ml_secret_key, 'notification' => $notification);
    //postID
    if ($remote_identifier) {
        $parameters['remote_identifier'] = "{$remote_identifier}";
    }
    $request = new WP_Http();
    $result = $request->request(MOBILOUD_PUSH_API_PUBLISH_URL, array('method' => 'POST', 'timeout' => 10, 'body' => $parameters));
    return false;
}
开发者ID:a-i-ko93,项目名称:ipl-foodblog,代码行数:29,代码来源:push-tags.php


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