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


PHP HTTPClient::setAuth方法代码示例

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


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

示例1: httpClient

 /**
  * Set up an HTTPClient with auth for our resource.
  *
  * @param string $method
  * @return HTTPClient
  */
 private function httpClient($method = 'GET')
 {
     $client = new HTTPClient($this->url);
     $client->setMethod($method);
     $client->setAuth($this->user, $this->pass);
     return $client;
 }
开发者ID:microcosmx,项目名称:experiments,代码行数:13,代码来源:atompub_test.php

示例2: doSubscribe

 protected function doSubscribe($mode)
 {
     $orig = clone $this;
     $this->verify_token = common_good_rand(16);
     if ($mode == 'subscribe') {
         $this->secret = common_good_rand(32);
     }
     $this->sub_state = $mode;
     $this->update($orig);
     unset($orig);
     try {
         $callback = common_local_url('pushcallback', array('feed' => $this->id));
         $headers = array('Content-Type: application/x-www-form-urlencoded');
         $post = array('hub.mode' => $mode, 'hub.callback' => $callback, 'hub.verify' => 'sync', 'hub.verify_token' => $this->verify_token, 'hub.secret' => $this->secret, 'hub.topic' => $this->uri);
         $client = new HTTPClient();
         if ($this->huburi) {
             $hub = $this->huburi;
         } else {
             if (common_config('feedsub', 'fallback_hub')) {
                 $hub = common_config('feedsub', 'fallback_hub');
                 if (common_config('feedsub', 'hub_user')) {
                     $u = common_config('feedsub', 'hub_user');
                     $p = common_config('feedsub', 'hub_pass');
                     $client->setAuth($u, $p);
                 }
             } else {
                 throw new FeedSubException('WTF?');
             }
         }
         $response = $client->post($hub, $headers, $post);
         $status = $response->getStatus();
         if ($status == 202) {
             common_log(LOG_INFO, __METHOD__ . ': sub req ok, awaiting verification callback');
             return true;
         } else {
             if ($status == 204) {
                 common_log(LOG_INFO, __METHOD__ . ': sub req ok and verified');
                 return true;
             } else {
                 if ($status >= 200 && $status < 300) {
                     common_log(LOG_ERR, __METHOD__ . ": sub req returned unexpected HTTP {$status}: " . $response->getBody());
                     return false;
                 } else {
                     common_log(LOG_ERR, __METHOD__ . ": sub req failed with HTTP {$status}: " . $response->getBody());
                     return false;
                 }
             }
         }
     } catch (Exception $e) {
         // wtf!
         common_log(LOG_ERR, __METHOD__ . ": error \"{$e->getMessage()}\" hitting hub {$this->huburi} subscribing to {$this->uri}");
         $orig = clone $this;
         $this->verify_token = '';
         $this->sub_state = 'inactive';
         $this->update($orig);
         unset($orig);
         return false;
     }
 }
开发者ID:Grasia,项目名称:bolotweet,代码行数:59,代码来源:FeedSub.php

示例3: doSubscribe

 /**
  * Setting to subscribe means it is _waiting_ to become active. This
  * cannot be done in a transaction because there is a chance that the
  * remote script we're calling (as in the case of PuSHpress) performs
  * the lookup _while_ we're POSTing data, which means the transaction
  * never completes (PushcallbackAction gets an 'inactive' state).
  *
  * @return boolean true when everything is ok (throws Exception on fail)
  * @throws Exception on failure, can be HTTPClient's or our own.
  */
 protected function doSubscribe($mode)
 {
     $orig = clone $this;
     if ($mode == 'subscribe') {
         $this->secret = common_random_hexstr(32);
     }
     $this->sub_state = $mode;
     $this->update($orig);
     unset($orig);
     try {
         $callback = common_local_url('pushcallback', array('feed' => $this->id));
         $headers = array('Content-Type: application/x-www-form-urlencoded');
         $post = array('hub.mode' => $mode, 'hub.callback' => $callback, 'hub.verify' => 'async', 'hub.verify_token' => 'Deprecated-since-PuSH-0.4', 'hub.secret' => $this->secret, 'hub.topic' => $this->getUri());
         $client = new HTTPClient();
         if ($this->huburi) {
             $hub = $this->huburi;
         } else {
             if (common_config('feedsub', 'fallback_hub')) {
                 $hub = common_config('feedsub', 'fallback_hub');
                 if (common_config('feedsub', 'hub_user')) {
                     $u = common_config('feedsub', 'hub_user');
                     $p = common_config('feedsub', 'hub_pass');
                     $client->setAuth($u, $p);
                 }
             } else {
                 throw new FeedSubException('Server could not find a usable PuSH hub.');
             }
         }
         $response = $client->post($hub, $headers, $post);
         $status = $response->getStatus();
         // PuSH specificed response status code
         if ($status == 202) {
             common_log(LOG_INFO, __METHOD__ . ': sub req ok, awaiting verification callback');
             return;
         } else {
             if ($status >= 200 && $status < 300) {
                 common_log(LOG_ERR, __METHOD__ . ": sub req returned unexpected HTTP {$status}: " . $response->getBody());
             } else {
                 common_log(LOG_ERR, __METHOD__ . ": sub req failed with HTTP {$status}: " . $response->getBody());
             }
         }
     } catch (Exception $e) {
         common_log(LOG_ERR, __METHOD__ . ": error \"{$e->getMessage()}\" hitting hub {$this->huburi} subscribing to {$this->getUri()}");
         // Reset the subscription state.
         $orig = clone $this;
         $this->sub_state = 'inactive';
         $this->update($orig);
         // Throw the Exception again.
         throw $e;
     }
     throw new ServerException("{$mode} request failed.");
 }
开发者ID:phpsource,项目名称:gnu-social,代码行数:62,代码来源:FeedSub.php

示例4: postToCollection

 function postToCollection($url, $activity)
 {
     $client = new HTTPClient($url);
     $client->setMethod('POST');
     $client->setAuth($this->username, $this->password);
     $client->setHeader('Content-Type', 'application/atom+xml;type=entry');
     $client->setBody($activity->asString(true, true, true));
     $response = $client->send();
     $status = $response->getStatus();
     $reason = $response->getReasonPhrase();
     if ($status >= 200 && $status < 300) {
         return true;
     } else {
         if ($status >= 400 && $status < 500) {
             // TRANS: Client exception thrown when post to collection fails with a 400 status.
             // TRANS: %1$s is a URL, %2$s is the status, %s$s is the fail reason.
             throw new ClientException(sprintf(_m('URLSTATUSREASON', '%1$s %2$s %3$s'), $url, $status, $reason));
         } else {
             if ($status >= 500 && $status < 600) {
                 // TRANS: Server exception thrown when post to collection fails with a 500 status.
                 // TRANS: %1$s is a URL, %2$s is the status, %s$s is the fail reason.
                 throw new ServerException(sprintf(_m('URLSTATUSREASON', '%1$s %2$s %3$s'), $url, $status, $reason));
             } else {
                 // That's unexpected.
                 // TRANS: Exception thrown when post to collection fails with a status that is not handled.
                 // TRANS: %1$s is a URL, %2$s is the status, %s$s is the fail reason.
                 throw new Exception(sprintf(_m('URLSTATUSREASON', '%1$s %2$s %3$s'), $url, $status, $reason));
             }
         }
     }
 }
开发者ID:microcosmx,项目名称:experiments,代码行数:31,代码来源:activitysink.php


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