本文整理汇总了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;
}
示例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;
}
示例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));
}
}
示例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";