當前位置: 首頁>>代碼示例>>PHP>>正文


PHP HttpRequest::addHeader方法代碼示例

本文整理匯總了PHP中HttpRequest::addHeader方法的典型用法代碼示例。如果您正苦於以下問題:PHP HttpRequest::addHeader方法的具體用法?PHP HttpRequest::addHeader怎麽用?PHP HttpRequest::addHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在HttpRequest的用法示例。


在下文中一共展示了HttpRequest::addHeader方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: format

 /**
  * @inheritdoc
  */
 public function format(HttpRequest $request)
 {
     $data = (array) $request->getData();
     $content = http_build_query($data, '', '&', $this->encodingType);
     if (strcasecmp('get', $request->getMethod()) === 0) {
         if (!empty($content)) {
             $url = $request->getUrl();
             $url .= strpos($url, '?') === false ? '?' : '&';
             $url .= $content;
             $request->setUrl($url);
         }
         return $request;
     }
     $request->addHeader('Content-Type', 'application/x-www-form-urlencoded');
     $request->setContent($content);
     return $request;
 }
開發者ID:cdcchen,項目名稱:curl-client,代碼行數:20,代碼來源:UrlEncodedFormatter.php

示例2: format

 /**
  * @param HttpRequest $request
  * @return HttpRequest
  */
 public function format(HttpRequest $request)
 {
     $request->addHeader('Content-Type', 'application/json; charset=UTF-8');
     $request->setContent(json_encode($request->getData(), $this->encodeOptions));
     return $request;
 }
開發者ID:cdcchen,項目名稱:curl-client,代碼行數:10,代碼來源:JsonFormatter.php

示例3: applyCookie

 /** 	 
  * @param HttpRequest $req
  */
 public function applyCookie($req)
 {
     // fetch cookies
     $host = $req->getHeader('host');
     $path = $req->getUrlParam('path');
     $cookies = $this->fetchCookieToSend($host, $path);
     if ($this !== $req) {
         $cookies = array_merge($cookies, $req->fetchCookieToSend($host, $path));
     }
     // add to header
     $req->setHeader('cookie', null);
     foreach (array_chunk(array_values($cookies), 3) as $chunk) {
         $req->addHeader('cookie', implode('; ', $chunk));
     }
 }
開發者ID:sophia2152,項目名稱:pspider,代碼行數:18,代碼來源:HttpClient.class.php

示例4: HttpRequest

echo "POST request\n";
$body = "This is a new note to myself.";
$request = new HttpRequest();
$request->setUrl($url);
$request->setMethod('POST');
$request->setBody($body);
$request->addHeader('Content-Type', 'text/plain');
$response = $http->doRequest($request);
//echo "Response: "; print_r($response);
echo $response->getStatus(), ': ', $response->getBody(), "\n";
echo "\n";
// PUT REQUEST
echo "PUT request\n";
$body = "An update to my original post.";
$request = new HttpRequest();
$request->setUrl($url);
$request->setMethod('PUT');
$request->setBody($body);
$request->addHeader('Content-Type', 'text/plain');
$response = $http->doRequest($request);
//echo "Response: "; print_r($response);
echo $response->getStatus(), ': ', $response->getBody(), "\n";
echo "\n";
// DELETE REQUEST
echo "DELETE request\n";
$request = new HttpRequest();
$request->setUrl($url);
$request->setMethod('DELETE');
$response = $http->doRequest($request);
echo $response->getStatus(), ': ', $response->getBody(), "\n";
echo "\n";
開發者ID:royopa,項目名稱:php5-http-client,代碼行數:31,代碼來源:example-rest.php


注:本文中的HttpRequest::addHeader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。