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


PHP HTTP_Request2::setHeader方法代码示例

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


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

示例1: setRequestHeaders

 /**
  * Sets the common headers required by CloudFront API
  * @param HTTP_Request2 $req
  */
 private function setRequestHeaders(HTTP_Request2 $req)
 {
     $date = gmdate("D, d M Y G:i:s T");
     $req->setHeader("Host", 'cloudfront.amazonaws.com');
     $req->setHeader("Date", $date);
     $req->setHeader("Authorization", $this->generateAuthKey($date));
     $req->setHeader("Content-Type", "text/xml");
 }
开发者ID:subchild,项目名称:CloudFront-PHP-Invalidator,代码行数:12,代码来源:CloudFront.php

示例2: request

 private function request($method, $path, $params = array())
 {
     $url = $this->api . rtrim($path, '/') . '/';
     if (!strcmp($method, "POST")) {
         $req = new HTTP_Request2($url, HTTP_Request2::METHOD_POST);
         $req->setHeader('Content-type: application/json');
         if ($params) {
             $req->setBody(json_encode($params));
         }
     } else {
         if (!strcmp($method, "GET")) {
             $req = new HTTP_Request2($url, HTTP_Request2::METHOD_GET);
             $url = $req->getUrl();
             $url->setQueryVariables($params);
         } else {
             if (!strcmp($method, "DELETE")) {
                 $req = new HTTP_Request2($url, HTTP_Request2::METHOD_DELETE);
                 $url = $req->getUrl();
                 $url->setQueryVariables($params);
             }
         }
     }
     $req->setAdapter('curl');
     $req->setConfig(array('timeout' => 30));
     $req->setAuth($this->auth_id, $this->auth_token, HTTP_Request2::AUTH_BASIC);
     $req->setHeader(array('Connection' => 'close', 'User-Agent' => 'PHPPlivo'));
     $r = $req->send();
     $status = $r->getStatus();
     $body = $r->getbody();
     $response = json_decode($body, true);
     return array("status" => $status, "response" => $response);
 }
开发者ID:davidangelcb,项目名称:voice,代码行数:32,代码来源:plivo.php

示例3: getRss

function getRss($url, $port, $timeout)
{
    $results = array('rss' => array(), 'error' => "");
    try {
        $request = new HTTP_Request2($url, HTTP_Request2::METHOD_POST);
        $request->setConfig("connect_timeout", $timeout);
        $request->setConfig("timeout", $timeout);
        $request->setHeader("user-agent", $_SERVER['HTTP_USER_AGENT']);
        $response = $request->send();
        if ($response->getStatus() == 200) {
            // パース
            $body = $response->getBody();
            if (substr($body, 0, 5) == "<?xml") {
                $results['rss'] = new MagpieRSS($body, "UTF-8");
            } else {
                throw new Exception("Not xml data");
            }
        } else {
            throw new Exception("Server returned status: " . $response->getStatus());
        }
    } catch (HTTP_Request2_Exception $e) {
        $results['error'] = $e->getMessage();
    } catch (Exception $e) {
        $results['error'] = $e->getMessage();
    }
    // タイムアウト戻し
    ini_set('default_socket_timeout', $oldtimeout);
    return $results;
}
开发者ID:homework-bazaar,项目名称:zencart-sugu,代码行数:29,代码来源:functions.php

示例4: send

 /**
  * Processes the reuqest through HTTP pipeline with passed $filters, 
  * sends HTTP request to the wire and process the response in the HTTP pipeline.
  * 
  * @param array $filters HTTP filters which will be applied to the request before
  *                       send and then applied to the response.
  * @param IUrl  $url     Request url.
  * 
  * @throws WindowsAzure\Common\ServiceException
  * 
  * @return string The response body
  */
 public function send($filters, $url = null)
 {
     if (isset($url)) {
         $this->setUrl($url);
         $this->_request->setUrl($this->_requestUrl->getUrl());
     }
     $contentLength = Resources::EMPTY_STRING;
     if (strtoupper($this->getMethod()) != Resources::HTTP_GET && strtoupper($this->getMethod()) != Resources::HTTP_DELETE && strtoupper($this->getMethod()) != Resources::HTTP_HEAD) {
         $contentLength = 0;
         if (!is_null($this->getBody())) {
             $contentLength = strlen($this->getBody());
         }
         $this->_request->setHeader(Resources::CONTENT_LENGTH, $contentLength);
     }
     foreach ($filters as $filter) {
         $this->_request = $filter->handleRequest($this)->_request;
     }
     $this->_response = $this->_request->send();
     $start = count($filters) - 1;
     for ($index = $start; $index >= 0; --$index) {
         $this->_response = $filters[$index]->handleResponse($this, $this->_response);
     }
     self::throwIfError($this->_response->getStatus(), $this->_response->getReasonPhrase(), $this->_response->getBody(), $this->_expectedStatusCodes);
     return $this->_response->getBody();
 }
开发者ID:southworkscom,项目名称:azure-sdk-for-php,代码行数:37,代码来源:HttpClient.php

示例5: sendRequest

 /**
  * Sends a request and returns a response
  *
  * @param CartRecover_Request $request
  * @return Cart_Recover_Response
  */
 public function sendRequest(CartRecover_Request $request)
 {
     $this->client->setUrl($request->getUri());
     $this->client->getUrl()->setQueryVariables($request->getParams());
     $this->client->setMethod($request->getMethod());
     $this->client->setHeader('Accept', 'application/json');
     $this->response = $this->client->send();
     if ($this->response->getHeader('Content-Type') != 'application/json') {
         throw new CartRecover_Exception_UnexpectedValueException("Unknown response format.");
     }
     $body = json_decode($this->response->getBody(), true);
     $response = new CartRecover_Response();
     $response->setRawResponse($this->response->getBody());
     $response->setBody($body);
     $response->setHeaders($this->response->getHeader());
     $response->setStatus($this->response->getReasonPhrase(), $this->response->getStatus());
     return $response;
 }
开发者ID:digital-canvas,项目名称:cart-recover-phpapi,代码行数:24,代码来源:PEAR.php

示例6: OXreqPUTforSendMail

 public function OXreqPUTforSendMail($url, $QueryVariables, $PutData, $returnResponseObject = false)
 {
     $QueryVariables['timezone'] = 'UTC';
     # all times are UTC,
     $request = new HTTP_Request2(OX_SERVER . $url, HTTP_Request2::METHOD_PUT);
     $request->setHeader('Content-type: text/javascript; charset=utf-8');
     $url = $request->getUrl();
     $url->setQueryVariables($QueryVariables);
     $request->setBody(utf8_encode($PutData));
     return $this->OXreq($request, $returnResponseObject);
 }
开发者ID:aniesshsethh,项目名称:z-push-ox,代码行数:11,代码来源:OXConnector.php

示例7: doHeadRequest

/**
 * Send an HTTP HEAD request for the given URL
 *
 * @param    string $url          URL to request
 * @param    string $errorMessage error message, if any (on return)
 * @return   int                  HTTP response code or 777 on error
 */
function doHeadRequest($url, &$errorMessage)
{
    $req = new HTTP_Request2($url, HTTP_Request2::METHOD_HEAD);
    $req->setHeader('User-Agent', 'Geeklog/' . VERSION);
    try {
        $response = $req->send();
        return $response->getStatus();
    } catch (HTTP_Request2_Exception $e) {
        $errorMessage = $e->getMessage();
        return 777;
    }
}
开发者ID:Geeklog-Core,项目名称:geeklog,代码行数:19,代码来源:sectest.php

示例8: getContents

function getContents($url, $start = 0, $userAgent = null)
{
    if ($start > 0) {
        $url .= "&start={$start}";
    }
    $http = new HTTP_Request2($url);
    $http->setAdapter('curl');
    if ($userAgent !== null) {
        $http->setHeader('User-Agent', $userAgent);
    }
    return $http->send();
}
开发者ID:shupp,项目名称:bandk,代码行数:12,代码来源:scrape.php

示例9: request

 /**
  * リソースリクエスト実行
  *
  * リモートURLにアクセスしてRSSだったら配列に、
  * そうでなかったらHTTP Body文字列をリソースとして扱います。
  *
  * @return BEAR_Ro
  * @throws BEAR_Resource_Execute_Exception
  */
 public function request()
 {
     $reqMethod = array();
     $reqMethod[BEAR_Resource::METHOD_CREATE] = HTTP_Request2::METHOD_POST;
     $reqMethod[BEAR_Resource::METHOD_READ] = HTTP_Request2::METHOD_GET;
     $reqMethod[BEAR_Resource::METHOD_UPDATE] = HTTP_Request2::METHOD_PUT;
     $reqMethod[BEAR_Resource::METHOD_DELETE] = HTTP_Request2::METHOD_DELETE;
     assert(isset($reqMethod[$this->_config['method']]));
     try {
         // 引数以降省略可能  config で proxy とかも設定可能
         $request = new HTTP_Request2($this->_config['uri'], $reqMethod[$this->_config['method']]);
         $request->setHeader("user-agent", 'BEAR/' . BEAR::VERSION);
         $request->setConfig("follow_redirects", true);
         if ($this->_config['method'] === BEAR_Resource::METHOD_CREATE || $this->_config['method'] === BEAR_Resource::METHOD_UPDATE) {
             foreach ($this->_config['values'] as $key => $value) {
                 $request->addPostParameter($key, $value);
             }
         }
         $response = $request->send();
         $code = $response->getStatus();
         $headers = $response->getHeader();
         if ($code == 200) {
             $body = $response->getBody();
         } else {
             $info = array('code' => $code, 'headers' => $headers);
             throw $this->_exception($response->getBody(), $info);
         }
     } catch (HTTP_Request2_Exception $e) {
         throw $this->_exception($e->getMessage());
     } catch (Exception $e) {
         throw $this->_exception($e->getMessage());
     }
     $rss = new XML_RSS($body, 'utf-8', 'utf-8');
     PEAR::setErrorHandling(PEAR_ERROR_RETURN);
     // @todo Panda::setPearErrorHandling(仮称)に変更しエラーを画面化しないようにする
     $rss->parse();
     $items = $rss->getItems();
     if (is_array($items) && count($items) > 0) {
         $body = $items;
         $headers = $rss->getChannelInfo();
         $headers['type'] = 'rss';
     } else {
         $headers['type'] = 'string';
         $body = array($body);
     }
     // UTF-8に
     $encode = mb_convert_variables('UTF-8', 'auto', $body);
     $ro = BEAR::factory('BEAR_Ro')->setBody($body)->setHeaders($headers);
     /* @var $ro BEAR_Ro */
     PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('Panda', 'onPearError'));
     return $ro;
 }
开发者ID:ryo88c,项目名称:BEAR.Saturday,代码行数:61,代码来源:Http.php

示例10: makeRequest

 /**
  * Make an API request.
  *
  * @param string $url    The URL to request agains.
  * @param string $method The request method.
  * @param mixed  $data   Optional, most likely a json encoded string.
  *
  * @return HTTP_Request2_Response
  * @throws HTTP_Request2_Exception In case something goes wrong. ;)
  */
 protected function makeRequest($url, $method = HTTP_Request2::METHOD_GET, $data = null)
 {
     if ($this->apiToken !== null) {
         $url .= '?u=' . $this->apiToken;
     }
     if (!$this->client instanceof HTTP_Request2) {
         $this->client = new HTTP_Request2();
     }
     $this->client->setHeader('Content-Type: application/json')->setAuth($this->username, $this->password)->setMethod($method)->setUrl($this->endpoint . $url);
     if ($data !== null) {
         $this->client->setBody($data);
     }
     $resp = $this->client->send();
     return $resp;
 }
开发者ID:hypertiny,项目名称:Services_UseKetchup,代码行数:25,代码来源:Common.php

示例11: Exception

 function get_data($prefix)
 {
     $url = $this->config->get_param($prefix . 'dezie_url');
     $body = "";
     $req = new HTTP_Request2($url);
     $req->setHeader('allowRedirects-Alive', true);
     // リダイレクトの許可設定(true/false)
     $req->setHeader('maxRedirects', 3);
     // リダイレクトの最大回数
     $response = $req->send();
     if ($response->getStatus() == 200) {
         $body = $response->getBody();
     }
     // 通信エラー、権限設定の変更などがあるとエラー画面が表示される。
     if (preg_match('/^<!DOCTYPE html>/', $body)) {
         throw new Exception("デヂエからのデータ取得に失敗しました。");
     }
     // デヂエからのデータに Cookie のデータが入ってしまうので削除
     $body = $this->remove_cookie($body);
     // デヂエから取得したレコードの中に改行が含まれている。
     // レコード中の改行は LF で行末は CR+LF なので前者だけ<br>に置換する。
     $body = $this->lf2br($body);
     return $body;
 }
开发者ID:cy-daisuke-senmyou,项目名称:SukumeRequestChecker,代码行数:24,代码来源:Dezie.php

示例12: getExternalData

 /**
  * A helper function that retrieves external metadata and caches it
  *
  * @param string   $url     URL to fetch
  * @param string   $id      ID of the entity to fetch
  * @param string[] $headers Optional headers to add to the request
  *
  * @return string Metadata (typically XML)
  * @throws Exception
  */
 protected function getExternalData($url, $id, $headers = [])
 {
     $cached = $this->db->uriCache->findOne(['_id' => $id, 'timestamp' => ['$gt' => new MongoDate(time() - $this->maxCacheAge)]]);
     if ($cached) {
         return $cached['data'];
     }
     if (is_null($this->request)) {
         $this->request = new HTTP_Request2($url, HTTP_Request2::METHOD_GET, ['ssl_verify_peer' => false, 'follow_redirects' => true]);
         $this->request->setHeader('Connection', 'Keep-Alive');
         $this->request->setHeader('User-Agent', 'RecordManager');
     } else {
         $this->request->setUrl($url);
     }
     if ($headers) {
         $this->request->setHeader($headers);
     }
     $response = null;
     for ($try = 1; $try <= $this->maxTries; $try++) {
         try {
             $response = $this->request->send();
         } catch (Exception $e) {
             if ($try < $this->maxTries) {
                 $this->log->log('getExternalData', "HTTP request for '{$url}' failed (" . $e->getMessage() . "), retrying in {$this->retryWait} seconds...", Logger::WARNING);
                 sleep($this->retryWait);
                 continue;
             }
             throw $e;
         }
         if ($try < $this->maxTries) {
             $code = $response->getStatus();
             if ($code >= 300 && $code != 404) {
                 $this->log->log('getExternalData', "HTTP request for '{$url}' failed ({$code}), retrying " . "in {$this->retryWait} seconds...", Logger::WARNING);
                 sleep($this->retryWait);
                 continue;
             }
         }
         break;
     }
     $code = is_null($response) ? 999 : $response->getStatus();
     if ($code >= 300 && $code != 404) {
         throw new Exception("Enrichment failed to fetch '{$url}': {$code}");
     }
     $data = $code != 404 ? $response->getBody() : '';
     $this->db->uriCache->save(['_id' => $id, 'timestamp' => new MongoDate(), 'data' => $data]);
     return $data;
 }
开发者ID:grharry,项目名称:RecordManager,代码行数:56,代码来源:Enrichment.php

示例13: callback

 public static function callback()
 {
     global $HTTP_CONFIG;
     //exchange the code you get for a access_token
     $code = $_GET['code'];
     $request = new HTTP_Request2(self::ACCESS_TOKEN_URL);
     $request->setMethod(HTTP_Request2::METHOD_POST);
     $request->setConfig($HTTP_CONFIG);
     $request->addPostParameter(['client_id' => GITHUB_APP_ID, 'client_secret' => GITHUB_APP_SECRET, 'code' => $code]);
     $request->setHeader('Accept', 'application/json');
     $response = $request->send();
     $response = json_decode($response->getBody());
     $access_token = $response->access_token;
     //Use this access token to get user details
     $request = new HTTP_Request2(self::USER_URL . '?access_token=' . $access_token, HTTP_Request2::METHOD_GET, $HTTP_CONFIG);
     $response = $request->send()->getBody();
     $userid = json_decode($response)->login;
     //get the userid
     //If such a user already exists in the database
     //Just log him in and don't touch the access_token
     $already_present_token = Token::get('github', $userid);
     if ($already_present_token) {
         $_SESSION['userid'] = $userid;
         redirect_to('/');
     }
     if (defined('GITHUB_ORGANIZATION')) {
         // perform the organization check
         $request = new HTTP_Request2(json_decode($response)->organizations_url . '?access_token=' . $access_token, HTTP_Request2::METHOD_GET, $HTTP_CONFIG);
         $response = $request->send()->getBody();
         //List of organizations
         $organizations_list = array_map(function ($repo) {
             return $repo->login;
         }, json_decode($response));
         if (in_array(GITHUB_ORGANIZATION, $organizations_list)) {
             $_SESSION['userid'] = $userid;
             Token::add('github', $userid, $access_token);
         } else {
             throw new Exception('You are not in the listed members.');
         }
     } else {
         $_SESSION['userid'] = $userid;
         Token::add('github', $userid, $access_token);
     }
     redirect_to('/');
 }
开发者ID:nsystem1,项目名称:leaderboard,代码行数:45,代码来源:github.php

示例14: postArticle

 /**
  * 記事を投稿する.
  *
  * @param string $title 記事タイトル
  * @param string $text 記事本文
  * @param string $category 記事カテゴリ
  * @return string $res 結果
  */
 public function postArticle($title, $text, $category)
 {
     try {
         $req = new HTTP_Request2();
         $req->setUrl(self::ROOT_END_POINT . $this->liveDoorId . "/" . self::END_POINT_TYPE_ARTICLE);
         $req->setConfig(array('ssl_verify_host' => false, 'ssl_verify_peer' => false));
         $req->setMethod(HTTP_Request2::METHOD_POST);
         $req->setAuth($this->liveDoorId, $this->atomPubPassword);
         $req->setBody($this->createBody($title, $text, $category));
         $req->setHeader('Expect', '');
         $res = $req->send();
     } catch (HTTP_Request2_Exception $e) {
         die($e->getMessage());
     } catch (Exception $e) {
         die($e->getMessage());
     }
     return $res;
 }
开发者ID:seiyaan,项目名称:LiveDoorBlogAtomPub,代码行数:26,代码来源:LiveDoorBlogAtomPub.php

示例15: sendPOST

 /**
  * Send a POST request to the specified URL with the specified payload.
  * @param string $url
  * @param string $data
  * @return string Remote data
  **/
 public function sendPOST($url, $data = array())
 {
     $data['_fake_status'] = '200';
     // Send the actual request.
     $this->instance->setHeader('User-Agent', sprintf(Imgur::$user_agent, Imgur::$key));
     $this->instance->setMethod('POST');
     $this->instance->setUrl($url);
     foreach ($data as $k => $v) {
         $this->instance->addPostParameter($k, $v);
     }
     try {
         /** @var HTTP_Request2_Response */
         $response = $this->instance->send();
         return $response->getBody();
     } catch (HTTP_Request2_Exception $e) {
         throw new Imgur_Exception("HTTP Request Failure", null, $e);
     } catch (Exception $e) {
         throw new Imgur_Exception("Unknown Failure during HTTP Request", null, $e);
     }
 }
开发者ID:plehnet,项目名称:Imgur-API-for-PHP,代码行数:26,代码来源:PEARHTTPRequest2.php


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