当前位置: 首页>>代码示例>>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;未经允许,请勿转载。