本文整理汇总了PHP中HttpResponse::setBody方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpResponse::setBody方法的具体用法?PHP HttpResponse::setBody怎么用?PHP HttpResponse::setBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpResponse
的用法示例。
在下文中一共展示了HttpResponse::setBody方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
if ($this->_isRequestMatching()) {
$this->_controller = $this->_getControllerInstance();
$this->_response->setBody($this->_callAction());
$this->_response->send();
}
}
示例2: curl
public static function curl($url, $httpMethod = "GET", $postFields = null, $headers = null)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $httpMethod);
if (ENABLE_HTTP_PROXY) {
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_PROXY, HTTP_PROXY_IP);
curl_setopt($ch, CURLOPT_PROXYPORT, HTTP_PROXY_PORT);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, is_array($postFields) ? self::getPostHttpBody($postFields) : $postFields);
if (self::$readTimeout) {
curl_setopt($ch, CURLOPT_TIMEOUT, self::$readTimeout);
}
if (self::$connectTimeout) {
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::$connectTimeout);
}
//https request
if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
if (is_array($headers) && 0 < count($headers)) {
$httpHeaders = self::getHttpHearders($headers);
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders);
}
$httpResponse = new HttpResponse();
$httpResponse->setBody(curl_exec($ch));
$httpResponse->setStatus(curl_getinfo($ch, CURLINFO_HTTP_CODE));
if (curl_errno($ch)) {
throw new ClientException("Speicified endpoint or uri is not valid.", "SDK.ServerUnreachable");
}
curl_close($ch);
return $httpResponse;
}
示例3: parseResponse
/**
* Parses the raw HTTP response and returns a response object
**/
protected function parseResponse($output, $ch = null)
{
$response = new HttpResponse();
if ($output) {
$lines = explode("\n", $output);
$isHeader = true;
$buffer = array();
foreach ($lines as $line) {
if ($isHeader) {
if (preg_match('/^\\s*$/', $line)) {
// Header/body separator
$isHeader = false;
} else {
// This is a real HTTP header
if (preg_match('/^([^:]+)\\:(.*)$/', $line, $matches)) {
//echo "HEADER: [", $matches[1], ']: [', $matches[2], "]\n";
$name = trim($matches[1]);
$value = trim($matches[2]);
$response->addHeader($name, $value);
} else {
// This is the status response
//echo "HEADER: ", trim($line), "\n";
if (preg_match('/^(HTTP\\/\\d\\.\\d) (\\d*) (.*)$/', trim($line), $matches)) {
$response->setStatus($matches[2]);
$response->setStatusMsg($matches[3]);
$response->setVersion($matches[1]);
}
}
}
} else {
$buffer[] = $line;
}
}
// The buffer is the HTTP Entity Body
$response->setBody(implode("\n", $buffer));
} else {
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($statusCode == 0) {
$response->setStatus(502);
$response->setStatusMsg('CURL Error');
} else {
$response->setStatus($statusCode);
$response->setStatusMsg('CURL Response');
}
}
return $response;
}