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


PHP wp_safe_remote_request函数代码示例

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


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

示例1: __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);
         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_safe_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:pankajsinghjarial,项目名称:SYLC-AMERICAN,代码行数:31,代码来源:class-feed.php

示例2: __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

示例3: oauth2callback

 /**
  * Internal callback, after OAuth
  */
 public function oauth2callback()
 {
     if (empty($_GET['code'])) {
         $error = array('provider' => self::PROVIDER_NAME, 'code' => 'oauth2callback_error', 'message' => 'No authorization code received', 'raw' => $_GET);
         $this->errorCallback($error);
         return;
     }
     $code = $_GET['code'];
     $url = self::TOKEN_ENDPOINT;
     $args = array('method' => 'POST', 'headers' => array('Authorization' => 'Basic ' . base64_encode($this->strategy['client_id'] . ':' . $this->strategy['client_secret'])), 'body' => array('code' => $code, 'redirect_uri' => $this->strategy['redirect_uri'], 'grant_type' => 'authorization_code'));
     $response = wp_safe_remote_request($url, $args);
     if (is_wp_error($response)) {
         $error = array('provider' => self::PROVIDER_NAME, 'code' => 'remote_request_error', 'raw' => $response->get_error_message());
         $this->errorCallback($error);
         return;
     }
     $responseHeaders = wp_remote_retrieve_body($response);
     $results = json_decode($response['body']);
     if (!empty($results) && !empty($results->access_token) && !empty($results->xoauth_yahoo_guid)) {
         $user_info = $this->userinfo($results->access_token, $results->xoauth_yahoo_guid);
         $email = $this->user_email($user_info);
         if (!$email) {
             $error = array('provider' => self::PROVIDER_NAME, 'code' => 'no_email_error', 'message' => 'No email in the user profile', 'raw' => array('response' => $response, 'headers' => $responseHeaders));
             $this->errorCallback($error);
             return;
         }
         $this->auth = array('uid' => $user_info->profile->guid, 'info' => array('nickname' => $user_info->profile->nickname, 'first_name' => $user_info->profile->givenName, 'last_name' => $user_info->profile->familyName, 'location' => $user_info->profile->location, 'image' => $user_info->profile->image->imageUrl, 'profileUrl' => $user_info->profile->profileUrl, 'email' => $email), 'credentials' => array('token' => $results->access_token, 'expires' => date('c', time() + $results->expires_in)), 'raw' => $user_info);
         $this->callback();
     } else {
         $error = array('provider' => self::PROVIDER_NAME, 'code' => 'access_token_error', 'message' => 'Failed when attempting to obtain access token', 'raw' => array('response' => $response, 'headers' => $responseHeaders));
         $this->errorCallback($error);
     }
 }
开发者ID:javolero,项目名称:dabba,代码行数:36,代码来源:SVYahooStrategy.php

示例4: request

 protected function request($url, $fields = '', $args = array())
 {
     $defaults = array('follow' => true, 'method' => 'GET', 'ssl_verify' => false, 'body' => '', 'httpversion' => '1.1', 'timeout' => 60);
     $args = array_merge($defaults, $args);
     $args['body'] = $fields;
     $response = wp_safe_remote_request($url, $args);
     if (is_wp_error($response)) {
         throw new PHP_Merchant_Exception(PHPME_HTTP_REQUEST_FAILED, $response->get_error_message());
     }
     return $response['body'];
 }
开发者ID:ashik968,项目名称:digiplot,代码行数:11,代码来源:http.php

示例5: yp_remote_request

function yp_remote_request($url)
{
    if (empty($url)) {
        return false;
    }
    $args = array('headers' => array('Accept-Encoding' => ''), 'timeout' => 30, 'user-agent' => 'Yellow Pencil Updater');
    $request = wp_safe_remote_request($url, $args);
    if ($request['response']['code'] == 200) {
        return $request['body'];
    }
    return false;
}
开发者ID:Arkon13,项目名称:magazin2,代码行数:12,代码来源:update-api.php

示例6: get_page

 /**
  * GET URL
  *
  * @param string $url
  * @param string $username
  * @param string $password
  * @param bool   $head
  * @return array
  */
 public function get_page($url, $username = '', $password = '', $head = false)
 {
     // Increase the timeout
     add_filter('http_request_timeout', array($this, 'bump_request_timeout'));
     $headers = array();
     $args = array();
     if (true === $head) {
         $args['method'] = 'HEAD';
     }
     if (!empty($username) && !empty($password)) {
         $headers['Authorization'] = 'Basic ' . base64_encode("{$username}:{$password}");
     }
     $args['headers'] = $headers;
     return wp_safe_remote_request($url, $args);
 }
开发者ID:leonardopires,项目名称:projectnami,代码行数:24,代码来源:class-wp-importer.php

示例7: http_request

 /**
  * Performs HTTP Request
  *
  * @since  1.0
  * @see wp_safe_remote_request()
  * @param string $method HTTP method to use for request
  * @throws Exception for Blank/invalid endpoint or HTTP method, WP HTTP API error
  */
 private function http_request($method)
 {
     // Check for blank endpoint or method
     if (!$this->endpoint || !$method) {
         throw new Exception(__('Endpoint and / or HTTP Method is blank.', WC_Twilio_SMS::TEXT_DOMAIN));
     }
     // Check that method is a valid http method
     if (!in_array($method, array('GET', 'POST', 'PUT', 'DELETE'))) {
         throw new Exception(__('Requested HTTP Method is invalid.', WC_Twilio_SMS::TEXT_DOMAIN));
     }
     // set the method
     $this->wp_remote_http_args['method'] = $method;
     // perform HTTP request with endpoint / args
     $this->response = wp_safe_remote_request(esc_url_raw($this->endpoint), $this->wp_remote_http_args);
     // WP HTTP API error like network timeout, etc
     if (is_wp_error($this->response)) {
         throw new Exception($this->response->get_error_message());
     }
     // Check for proper response / body
     if (!isset($this->response['response'])) {
         throw new Exception(__('Empty Response', WC_Twilio_SMS::TEXT_DOMAIN));
     }
     if (!isset($this->response['body'])) {
         throw new Exception(__('Empty Body', WC_Twilio_SMS::TEXT_DOMAIN));
     }
 }
开发者ID:bself,项目名称:nuimage-wp,代码行数:34,代码来源:class-wc-twilio-sms-api.php

示例8: remote_request

 /**
  * Helper function to query the marketplace API via wp_remote_request.
  *
  * @param     string      The url to access.
  * @return    object      The results of the wp_remote_request request.
  *
  * @access    private
  * @since     1.0
  */
 protected function remote_request($url)
 {
     if (empty($url)) {
         return false;
     }
     $args = array('headers' => array('Accept-Encoding' => '', 'Authorization' => sprintf('Bearer %s', $this->personal_token)), 'timeout' => 30, 'user-agent' => 'Toolkit/1.7.3');
     $request = wp_safe_remote_request($url, $args);
     if (is_wp_error($request)) {
         echo $request->get_error_message();
         return false;
     }
     $data = json_decode($request['body']);
     if ($request['response']['code'] == 200) {
         return $data;
     } else {
         $this->set_error('http_code', $request['response']['code']);
     }
     if (isset($data->error)) {
         $this->set_error('api_error', $data->error);
     }
     return false;
 }
开发者ID:jamesckemp,项目名称:envato-api,代码行数:31,代码来源:class-envato-api.php

示例9: httpRequest

 /**
  * Simple server-side HTTP request with file_get_contents
  * Provides basic HTTP calls.
  * See serverGet() and serverPost() for wrapper functions of httpRequest()
  *
  * Notes:
  * Reluctant to use any more advanced transport like cURL for the time being to not
  *     having to set cURL as being a requirement.
  * Strategy is to provide own HTTP transport handler if requiring more advanced support.
  *
  * @param string $url Full URL to load
  * @param array $options Stream context options (http://php.net/stream-context-create)
  * @param string $responseHeaders Response headers after HTTP call. Useful for error debugging.
  * @return string Content resulted from request, without headers
  */
 public static function httpRequest($url, $options = null, &$responseHeaders = null)
 {
     $wp_http_args = array('method' => !empty($options['http']['method']) ? $options['http']['method'] : 'GET', 'timeout' => MINUTE_IN_SECONDS, 'redirection' => 0, 'httpversion' => '1.0', 'sslverify' => true, 'blocking' => true, 'body' => !empty($options['http']['content']) ? $options['http']['content'] : '', 'headers' => !empty($options['http']['header']) ? $options['http']['header'] : array(), 'cookies' => array());
     // perform request
     $response = wp_safe_remote_request($url, $wp_http_args);
     // immediately get response headers
     $responseHeaders = wp_remote_retrieve_body($response);
     if (is_wp_error($response)) {
         // network timeout, etc
         $content = $response->get_error_message();
     } else {
         $content = wp_remote_retrieve_body($response);
     }
     return $content;
 }
开发者ID:javolero,项目名称:dabba,代码行数:30,代码来源:OpauthStrategy.php

示例10: delete

 /**
  * Sends a DELETE request for the given article and bundles.
  *
  * @param string $url
  * @return mixed
  * @since 0.2.0
  */
 public function delete($url)
 {
     // Build the delete request args
     $args = array('headers' => array('Authorization' => $this->sign($url, 'DELETE')), 'method' => 'DELETE');
     // Allow filtering and merge with the default args
     $args = apply_filters('apple_news_delete_args', wp_parse_args($args, $this->default_args));
     // Perform the delete
     $response = wp_safe_remote_request(esc_url_raw($url), $args);
     // NULL is a valid response for DELETE
     if (is_null($response)) {
         return null;
     }
     // Parse and return the response
     return $this->parse_response($response);
 }
开发者ID:mattheu,项目名称:apple-news,代码行数:22,代码来源:class-request.php

示例11: request

 public static function request($url, $params = null, $args = array())
 {
     if (!empty($params)) {
         $url = add_query_arg($params, $url);
     }
     $defaults = array('method' => 'GET');
     $args = wp_parse_args($args, $defaults);
     if (strpos($url, 'http') !== 0) {
         $url = Sputnik::API_BASE . $url;
     }
     $args['timeout'] = 25;
     $args['headers']['user-agent'] = 'WP eCommerce Marketplace: ' . WPSC_VERSION;
     $args['headers']['X-WP-Domain'] = self::domain();
     $request = wp_safe_remote_request(esc_url_raw($url), $args);
     if (is_wp_error($request)) {
         throw new Exception($request->get_error_message());
     }
     if ($request['response']['code'] != 200) {
         throw new Exception($request['body'], $request['response']['code']);
     }
     $result = json_decode($request['body']);
     if ($result === null) {
         throw new Exception($request['body'], $request['response']['code']);
     }
     $request['body'] = $result;
     return $request;
 }
开发者ID:RJHanson292,项目名称:WP-e-Commerce,代码行数:27,代码来源:API.php

示例12: http

 protected function http($url, $method, $postfields = NULL)
 {
     $args = array('method' => $method, 'user-agent' => 'WP eCommerce Marketplace: ' . WPSC_VERSION);
     switch ($method) {
         case 'POST':
             if (!empty($postfields)) {
                 $args['body'] = $postfields;
             }
             break;
     }
     $args['headers'] = array('X-WP-Domain' => Sputnik_API::domain());
     $response = wp_safe_remote_request($url, $args);
     if (is_wp_error($response)) {
         throw new Exception($response->get_error_message());
     }
     if ($response['response']['code'] != 200) {
         throw new Exception($response['body']);
     }
     return $response['body'];
 }
开发者ID:ashik968,项目名称:digiplot,代码行数:20,代码来源:Auth.php

示例13: request

 private function request($url, $method, $parameters)
 {
     $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $method, $url, $parameters);
     $request->sign_request($this->sha1_method, $this->consumer, $this->token);
     $args = array('sslverify' => false, 'method' => $method, 'timeout' => 15);
     switch ($method) {
         case 'GET':
             $url = $request->to_url();
             $response = wp_safe_remote_get($url, $args);
             break;
         default:
             $url = $request->get_normalized_http_url();
             $args = wp_parse_args(array('body' => $request->to_postdata()), $args);
             $response = wp_safe_remote_request($url, $args);
             break;
     }
     $this->response_code = wp_remote_retrieve_response_code($response);
     $this->response_headers = wp_remote_retrieve_headers($response);
     /* Check if we have a valid response */
     if (200 == $this->response_code) {
         if ($response_body = wp_remote_retrieve_body($response)) {
             /* Decode the response body */
             $result = json_decode(trim($response_body), true);
             /* Check if we failed to decode the response, or the response contains errors */
             if (is_null($result) || isset($result['errors'])) {
                 $this->response_errors = isset($result['errors']) ? $result['errors'] : null;
                 return false;
             }
             return $result;
         }
     }
     return false;
 }
开发者ID:yemingyuen,项目名称:mingsg,代码行数:33,代码来源:class-twitter-oauth.php

示例14: http

 /**
  * Make an HTTP request
  *
  * @internal Adapted for WP_Http
  * @return API results
  */
 function http($url, $method, $postfields = NULL)
 {
     $this->http_info = null;
     // this is never used
     $options = array('method' => $method, 'timeout' => $this->timeout, 'user-agent' => $this->useragent, 'sslverify' => $this->ssl_verifypeer);
     switch ($method) {
         case 'POST':
             if (!empty($postfields)) {
                 $options['body'] = $postfields;
             }
             break;
         case 'DELETE':
             if (!empty($postfields)) {
                 $url = "{$url}?{$postfields}";
             }
     }
     $response = wp_safe_remote_request($url, $options);
     if (is_wp_error($response)) {
         $this->http_code = null;
         $this->http_header = array();
         return false;
     }
     $this->http_code = $response['response']['code'];
     $this->http_header = $response['headers'];
     return $response['body'];
 }
开发者ID:ashik968,项目名称:digiplot,代码行数:32,代码来源:TwitterOAuth.php

示例15: do_remote_request

 /**
  * Simple wrapper for wp_remote_request() so child classes can override this
  * and provide their own transport mechanism if needed, e.g. a custom
  * cURL implementation
  *
  * @since 2.2.0
  * @param string $request_uri
  * @param string $request_args
  * @return array|WP_Error
  */
 protected function do_remote_request($request_uri, $request_args)
 {
     return wp_safe_remote_request($request_uri, $request_args);
 }
开发者ID:javolero,项目名称:dabba,代码行数:14,代码来源:class-sv-wc-api-base.php


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