本文整理匯總了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";