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


PHP HTTPClient::setHeader方法代码示例

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


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

示例1: onStartNoticeSave

 function onStartNoticeSave($notice)
 {
     $args = $this->testArgs($notice);
     common_debug("Blogspamnet args = " . print_r($args, TRUE));
     $requestBody = xmlrpc_encode_request('testComment', array($args));
     $request = new HTTPClient($this->baseUrl, HTTPClient::METHOD_POST);
     $request->setHeader('Content-Type', 'text/xml');
     $request->setBody($requestBody);
     $httpResponse = $request->send();
     $response = xmlrpc_decode($httpResponse->getBody());
     if (xmlrpc_is_fault($response)) {
         throw new ServerException("{$response['faultString']} ({$response['faultCode']})", 500);
     } else {
         common_debug("Blogspamnet results = " . $response);
         if (preg_match('/^ERROR(:(.*))?$/', $response, $match)) {
             throw new ServerException(sprintf(_("Error from %s: %s"), $this->baseUrl, $match[2]), 500);
         } else {
             if (preg_match('/^SPAM(:(.*))?$/', $response, $match)) {
                 throw new ClientException(sprintf(_("Spam checker results: %s"), $match[2]), 400);
             } else {
                 if (preg_match('/^OK$/', $response)) {
                     // don't do anything
                 } else {
                     throw new ServerException(sprintf(_("Unexpected response from %s: %s"), $this->baseUrl, $response), 500);
                 }
             }
         }
     }
     return true;
 }
开发者ID:microcosmx,项目名称:experiments,代码行数:30,代码来源:BlogspamNetPlugin.php

示例2: fromHcardUrl

 static function fromHcardUrl($url)
 {
     $client = new HTTPClient();
     $client->setHeader('Accept', 'text/html,application/xhtml+xml');
     $response = $client->get($url);
     if (!$response->isOk()) {
         return null;
     }
     return self::hcardHints($response->getBody(), $response->getUrl());
 }
开发者ID:Br3nda,项目名称:StatusNet,代码行数:10,代码来源:discoveryhints.php

示例3: updateProfileURL

 /**
  * Look up and if necessary create an Ostatus_profile for the remote entity
  * with the given profile page URL. This should never return null -- you
  * will either get an object or an exception will be thrown.
  *
  * @param string $profile_url
  * @return Ostatus_profile
  * @throws Exception on various error conditions
  * @throws OStatusShadowException if this reference would obscure a local user/group
  */
 public static function updateProfileURL($profile_url, $hints = array())
 {
     $oprofile = null;
     $hints['profileurl'] = $profile_url;
     // Fetch the URL
     // XXX: HTTP caching
     $client = new HTTPClient();
     $client->setHeader('Accept', 'text/html,application/xhtml+xml');
     $response = $client->get($profile_url);
     if (!$response->isOk()) {
         // TRANS: Exception. %s is a profile URL.
         throw new Exception(sprintf(_('Could not reach profile page %s.'), $profile_url));
     }
     // Check if we have a non-canonical URL
     $finalUrl = $response->getUrl();
     if ($finalUrl != $profile_url) {
         $hints['profileurl'] = $finalUrl;
     }
     // Try to get some hCard data
     $body = $response->getBody();
     $hcardHints = DiscoveryHints::hcardHints($body, $finalUrl);
     if (!empty($hcardHints)) {
         $hints = array_merge($hints, $hcardHints);
     }
     // Check if they've got an LRDD header
     $lrdd = LinkHeader::getLink($response, 'lrdd', 'application/xrd+xml');
     try {
         $xrd = new XML_XRD();
         $xrd->loadFile($lrdd);
         $xrdHints = DiscoveryHints::fromXRD($xrd);
         $hints = array_merge($hints, $xrdHints);
     } catch (Exception $e) {
         // No hints available from XRD
     }
     // If discovery found a feedurl (probably from LRDD), use it.
     if (array_key_exists('feedurl', $hints)) {
         return self::ensureFeedURL($hints['feedurl'], $hints);
     }
     // Get the feed URL from HTML
     $discover = new FeedDiscovery();
     $feedurl = $discover->discoverFromHTML($finalUrl, $body);
     if (!empty($feedurl)) {
         $hints['feedurl'] = $feedurl;
         return self::ensureFeedURL($feedurl, $hints);
     }
     // TRANS: Exception. %s is a URL.
     throw new Exception(sprintf(_m('Could not find a feed URL for profile page %s.'), $finalUrl));
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:58,代码来源:update_ostatus_profiles.php

示例4: onStartNoticeSave

 function onStartNoticeSave($notice)
 {
     $args = $this->testArgs($notice);
     common_debug("Blogspamnet args = " . print_r($args, TRUE));
     $requestBody = xmlrpc_encode_request('testComment', array($args));
     $request = new HTTPClient($this->baseUrl, HTTPClient::METHOD_POST);
     $request->setHeader('Content-Type', 'text/xml');
     $request->setBody($requestBody);
     $httpResponse = $request->send();
     $response = xmlrpc_decode($httpResponse->getBody());
     if (xmlrpc_is_fault($response)) {
         throw new ServerException("{$response['faultString']} ({$response['faultCode']})", 500);
     } else {
         common_debug("Blogspamnet results = " . $response);
         if (preg_match('/^ERROR(:(.*))?$/', $response, $match)) {
             // TRANS: Server exception thrown when blogspam.net returns error status.
             // TRANS: %1$s is the base URL, %2$s is the error (unknown contents; no period).
             throw new ServerException(sprintf(_m('Error from %1$s: %2$s'), $this->baseUrl, $match[2]), 500);
         } else {
             if (preg_match('/^SPAM(:(.*))?$/', $response, $match)) {
                 // TRANS: Server exception thrown when blogspam.net returns spam status.
                 // TRANS: Does not end with period because of unknown contents for %s (spam match).
                 throw new ClientException(sprintf(_m('Spam checker results: %s'), $match[2]), 400);
             } else {
                 if (preg_match('/^OK$/', $response)) {
                     // don't do anything
                 } else {
                     // TRANS: Server exception thrown when blogspam.net returns an unexpected status.
                     // TRANS: %1$s is the base URL, %2$s is the response (unknown contents; no period).
                     throw new ServerException(sprintf(_m('Unexpected response from %1$s: %2$s'), $this->baseUrl, $response), 500);
                 }
             }
         }
     }
     return true;
 }
开发者ID:Grasia,项目名称:bolotweet,代码行数:36,代码来源:BlogspamNetPlugin.php

示例5: ensureProfileURL

 /**
  * Look up and if necessary create an Ostatus_profile for the remote entity
  * with the given profile page URL. This should never return null -- you
  * will either get an object or an exception will be thrown.
  *
  * @param string $profile_url
  * @return Ostatus_profile
  * @throws Exception on various error conditions
  * @throws OStatusShadowException if this reference would obscure a local user/group
  */
 public static function ensureProfileURL($profile_url, $hints = array())
 {
     $oprofile = self::getFromProfileURL($profile_url);
     if (!empty($oprofile)) {
         return $oprofile;
     }
     $hints['profileurl'] = $profile_url;
     // Fetch the URL
     // XXX: HTTP caching
     $client = new HTTPClient();
     $client->setHeader('Accept', 'text/html,application/xhtml+xml');
     $response = $client->get($profile_url);
     if (!$response->isOk()) {
         throw new Exception("Could not reach profile page: " . $profile_url);
     }
     // Check if we have a non-canonical URL
     $finalUrl = $response->getUrl();
     if ($finalUrl != $profile_url) {
         $hints['profileurl'] = $finalUrl;
         $oprofile = self::getFromProfileURL($finalUrl);
         if (!empty($oprofile)) {
             return $oprofile;
         }
     }
     // Try to get some hCard data
     $body = $response->getBody();
     $hcardHints = DiscoveryHints::hcardHints($body, $finalUrl);
     if (!empty($hcardHints)) {
         $hints = array_merge($hints, $hcardHints);
     }
     // Check if they've got an LRDD header
     $lrdd = LinkHeader::getLink($response, 'lrdd', 'application/xrd+xml');
     if (!empty($lrdd)) {
         $xrd = Discovery::fetchXrd($lrdd);
         $xrdHints = DiscoveryHints::fromXRD($xrd);
         $hints = array_merge($hints, $xrdHints);
     }
     // If discovery found a feedurl (probably from LRDD), use it.
     if (array_key_exists('feedurl', $hints)) {
         return self::ensureFeedURL($hints['feedurl'], $hints);
     }
     // Get the feed URL from HTML
     $discover = new FeedDiscovery();
     $feedurl = $discover->discoverFromHTML($finalUrl, $body);
     if (!empty($feedurl)) {
         $hints['feedurl'] = $feedurl;
         return self::ensureFeedURL($feedurl, $hints);
     }
     throw new Exception("Could not find a feed URL for profile page " . $finalUrl);
 }
开发者ID:sukhjindersingh,项目名称:PHInest-Solutions,代码行数:60,代码来源:Ostatus_profile.php

示例6: httpRequest

 /**
  * Make a HTTP request.
  *
  * @param string $url    Where to make the
  * @param array  $params post parameters
  *
  * @return mixed the request
  */
 function httpRequest($url, $params = null)
 {
     $request = new HTTPClient($url);
     $request->setConfig(array('connect_timeout' => 120, 'timeout' => 120, 'follow_redirects' => true, 'ssl_verify_peer' => false, 'ssl_verify_host' => false));
     // Twitter is strict about accepting invalid "Expect" headers
     $request->setHeader('Expect', '');
     if (isset($params)) {
         $request->setMethod(HTTP_Request2::METHOD_POST);
         $request->setBody($params);
     }
     try {
         $response = $request->send();
         $code = $response->getStatus();
         if ($code < 200 || $code >= 400) {
             throw new OAuthClientException($response->getBody(), $code);
         }
         return $response->getBody();
     } catch (Exception $e) {
         throw new OAuthClientException($e->getMessage(), $e->getCode());
     }
 }
开发者ID:himmelex,项目名称:NTW,代码行数:29,代码来源:oauthclient.php

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

示例8: quickGet

 /**
  * Quick static function to GET a URL
  */
 public static function quickGet($url, $accept = null, $params = array())
 {
     if (!empty($params)) {
         $params = http_build_query($params, null, '&');
         if (strpos($url, '?') === false) {
             $url .= '?' . $params;
         } else {
             $url .= '&' . $params;
         }
     }
     $client = new HTTPClient();
     if (!is_null($accept)) {
         $client->setHeader('Accept', $accept);
     }
     $response = $client->get($url);
     if (!$response->isOk()) {
         // TRANS: Exception. %s is a profile URL.
         throw new Exception(sprintf(_m('Could not GET URL %s.'), $url), $response->getStatus());
     }
     return $response->getBody();
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:24,代码来源:httpclient.php

示例9: quickGet

 /**
  * Quick static function to GET a URL
  */
 public static function quickGet($url, $accept = null)
 {
     $client = new HTTPClient();
     if (!is_null($accept)) {
         $client->setHeader('Accept', $accept);
     }
     $response = $client->get($url);
     if (!$response->isOk()) {
         // TRANS: Exception. %s is a profile URL.
         throw new Exception(sprintf(_m('Could not GET URL %s.'), $url), $response->getStatus());
     }
     return $response->getBody();
 }
开发者ID:phpsource,项目名称:gnu-social,代码行数:16,代码来源:httpclient.php

示例10: postJSON

 function postJSON($url, $body)
 {
     $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, 'POST', $url);
     $request->sign_request($this->sha1_method, $this->consumer, $this->token);
     $hclient = new HTTPClient($url);
     $hclient->setConfig(array('connect_timeout' => 120, 'timeout' => 120, 'follow_redirects' => true, 'ssl_verify_peer' => false, 'ssl_verify_host' => false));
     $hclient->setMethod(HTTP_Request2::METHOD_POST);
     $hclient->setBody(json_encode($body));
     $hclient->setHeader('Content-Type', 'application/json');
     $hclient->setHeader($request->to_header());
     // Twitter is strict about accepting invalid "Expect" headers
     // No reason not to clear it still here -ESP
     $hclient->setHeader('Expect', '');
     try {
         $response = $hclient->send();
         $code = $response->getStatus();
         if (!$response->isOK()) {
             throw new OAuthClientException($response->getBody(), $code);
         }
         return $response;
     } catch (Exception $e) {
         throw new OAuthClientException($e->getMessage(), $e->getCode());
     }
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:24,代码来源:spamfilter.php


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