本文整理汇总了PHP中HttpResponse类的典型用法代码示例。如果您正苦于以下问题:PHP HttpResponse类的具体用法?PHP HttpResponse怎么用?PHP HttpResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HttpResponse类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Creates a new response
*
* @param peer.http.HttpResponse response
* @param webservices.rest.ResponseReader reader
* @param var type (Deprecated)
*/
public function __construct(HttpResponse $response, ResponseReader $reader = NULL, $type = NULL)
{
$this->response = $response;
$this->reader = $reader;
$this->type = $type;
$this->input = $response->getInputStream();
}
开发者ID:melogamepay,项目名称:xp-framework,代码行数:14,代码来源:RestResponse.class.php
示例2: testGetters
public function testGetters()
{
$response = new HttpResponse(200, array('Age: 42'), 'Hey');
$this->assertEquals(200, $response->getStatus());
$this->assertEquals(array('Age: 42'), $response->getHeaders());
$this->assertEquals('Hey', $response->getBody());
}
开发者ID:phpcurl,项目名称:curlhttp,代码行数:7,代码来源:HttpResponseTest.php
示例3: post
public static function post($url, $params, $auth)
{
try {
if (!function_exists("curl_init") && !function_exists("curl_setopt") && !function_exists("curl_exec") && !function_exists("curl_close")) {
throw new Exception('CURL is required.');
}
$data = array("data" => $params->getJSONEncode(), "version" => Config::version);
$httpResponse = new HttpResponse();
ob_start();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, self::get_furl($url));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data, '', '&'));
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, '0');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, '0');
curl_setopt($ch, CURLOPT_HTTPHEADER, $auth);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, Config::timeout);
curl_exec($ch);
$httpResponse->setResponse(urldecode(ob_get_contents()));
$httpResponse->setCode(curl_getinfo($ch, CURLINFO_HTTP_CODE));
ob_end_clean();
if (curl_errno($ch)) {
curl_close($ch);
throw new Exception(curl_error($ch));
}
curl_close($ch);
return $httpResponse;
} catch (Exception $e) {
curl_close($ch);
throw new HttpException($e->getMessage());
}
}
开发者ID:lnoering,项目名称:bcash-transparente,代码行数:32,代码来源:HttpServiceImpl.php
示例4: render
/**
* @param string
* @param array
* @return HttpRequest
*/
public function render($template, $context)
{
$render = $this->get('render');
$response = new HttpResponse();
$response->setData($render->render($template, $context));
return $response;
}
开发者ID:Everus,项目名称:wbf.test,代码行数:12,代码来源:controller.php
示例5: __construct
/**
* Creates a new response
*
* @param peer.http.HttpResponse response
* @param webservices.rest.RestDeserializer deserializer
* @param lang.Type type
*/
public function __construct(HttpResponse $response, RestDeserializer $deserializer = NULL, Type $type = NULL)
{
$this->response = $response;
$this->deserializer = $deserializer;
$this->type = $type;
$this->input = $response->getInputStream();
}
开发者ID:Gamepay,项目名称:xp-framework,代码行数:14,代码来源:RestResponse.class.php
示例6: dispatch
public function dispatch(Request $request, Response $response = null)
{
if (!$response) {
$response = new HttpResponse();
}
$response->setContent(__METHOD__);
return $response;
}
开发者ID:haoyanfei,项目名称:zf2,代码行数:8,代码来源:PathController.php
示例7: test_set_body_with_empty_string
function test_set_body_with_empty_string()
{
$response = new HttpResponse(200);
$headers = array();
$headers['content-encoding'] = 'gzip';
$response->headers = $headers;
$response->body = "";
$this->assertTrue($response->is_success(), 'Should have handled empty body without causing error');
}
开发者ID:risis-eu,项目名称:RISIS_LinkedDataAPI,代码行数:9,代码来源:httpresponse.test.php
示例8: makeRequest
public static function makeRequest(HttpRequest $request)
{
$requestUri = $request->getRequestUri()->getUri();
// if the request is towards a file URL, return the response constructed
// from file
if (0 === strpos($requestUri, "file:///")) {
return HttpResponse::fromFile($requestUri);
}
$httpResponse = new HttpResponse();
$curlChannel = curl_init();
curl_setopt($curlChannel, CURLOPT_URL, $requestUri);
curl_setopt($curlChannel, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curlChannel, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlChannel, CURLOPT_TIMEOUT, 10);
if ($request->getRequestMethod() === "POST") {
curl_setopt($curlChannel, CURLOPT_POST, 1);
curl_setopt($curlChannel, CURLOPT_POSTFIELDS, $request->getContent());
}
$basicAuthUser = $request->getBasicAuthUser();
$basicAuthPass = $request->getBasicAuthPass();
if (NULL !== $basicAuthUser) {
$request->setHeader("Authorization", "Basic " . base64_encode($basicAuthUser . ":" . $basicAuthPass));
}
// Including HTTP headers in request
$headers = $request->getHeaders(TRUE);
if (!empty($headers)) {
curl_setopt($curlChannel, CURLOPT_HTTPHEADER, $headers);
}
// Connect to SSL/TLS server, validate certificate and host
if ($request->getRequestUri()->getScheme() === "https") {
curl_setopt($curlChannel, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($curlChannel, CURLOPT_SSL_VERIFYHOST, 2);
}
// Callback to extract all the HTTP headers from the response...
// In order to really correctly parse HTTP headers one would have to look at RFC 2616...
curl_setopt($curlChannel, CURLOPT_HEADERFUNCTION, function ($curlChannel, $header) use($httpResponse) {
// Ignore Status-Line (RFC 2616, section 6.1)
if (0 === preg_match('|^HTTP/\\d+.\\d+ [1-5]\\d\\d|', $header)) {
// Only deal with header lines that contain a colon
if (strpos($header, ":") !== FALSE) {
// Only deal with header lines that contain a colon
list($key, $value) = explode(":", trim($header));
$httpResponse->setHeader(trim($key), trim($value));
}
}
return strlen($header);
});
$output = curl_exec($curlChannel);
if ($errorNumber = curl_errno($curlChannel)) {
throw new OutgoingHttpRequestException(curl_error($curlChannel));
}
$httpResponse->setStatusCode(curl_getinfo($curlChannel, CURLINFO_HTTP_CODE));
$httpResponse->setContent($output);
curl_close($curlChannel);
return $httpResponse;
}
开发者ID:fkooman,项目名称:php-rest-service,代码行数:56,代码来源:OutgoingHttpRequest.php
示例9: __construct
/**
* Construct the OAuth 2 error using a response object
*
* @param \HttpResponse $response The response object
*/
public function __construct($response)
{
$response->error = $this;
$this->response = $response;
$parsedResponse = $response->parse();
if (is_array($parsedResponse)) {
$this->code = isset($parsedResponse['error']) ? $parsedResponse['error'] : 0;
$this->message = isset($parsedResponse['error_description']) ? $parsedResponse['error_description'] : null;
}
}
开发者ID:76design,项目名称:oauth2-php,代码行数:15,代码来源:Error.php
示例10: send
public function send($url)
{
curl_setopt($this->handler, CURLOPT_URL, $url);
$this->response_body = curl_exec($this->handler);
$response = HttpResponse::separate($this->response_body, array('header_size' => curl_getinfo($this->handler, CURLINFO_HEADER_SIZE)));
return $response;
}
开发者ID:simsalabim,项目名称:rasp_fu,代码行数:7,代码来源:requester.php
示例11: HttpServletResponse
function HttpServletResponse(&$servletcontext)
{
parent::HttpResponse();
if (ServletContext::validClass($servletcontext)) {
$this->context =& $servletcontext;
}
}
开发者ID:alexpagnoni,项目名称:jphp,代码行数:7,代码来源:HttpServletResponse.php
示例12: getRedirectResponse
public function getRedirectResponse()
{
if (!$this->isRedirect()) {
throw new RuntimeException('This response does not support redirection.');
}
$output = json_encode($this->getData());
return HttpResponse::create($output);
}
开发者ID:aunn,项目名称:omnipay-txprocess,代码行数:8,代码来源:Response.php
示例13: _getResponse
private function _getResponse($request)
{
$response = [];
$request['httpStatus'] = "200";
$request['httpReasonPhrase'] = "OK";
$request['body'] = "";
if (file_exists('.' . $request['uri']) === true) {
$request['body'] = file_get_contents('.' . $request['uri']);
} else {
$request['httpStatus'] = "400";
$request['httpReasonPhrase'] = "NOT FOUND";
}
$httpResponse = new HttpResponse($request);
$response['header'] = $httpResponse->getResponseHeader();
$response['body'] = $httpResponse->getResponseBody();
return $response;
}
开发者ID:sonedayuya,项目名称:pserver,代码行数:17,代码来源:server.php
示例14: test_HttpResponse
/**
* Test HttpResponse.
*/
function test_HttpResponse()
{
HttpResponse::setCache(true);
HttpResponse::setContentType('application/pdf');
HttpResponse::setContentDisposition("test.pdf", false);
HttpResponse::setFile('sheet.pdf');
HttpResponse::send();
}
开发者ID:jkribeiro,项目名称:PHPHttpCompatibility,代码行数:11,代码来源:snippets.php
示例15: getResponse
/**
* Executes an HTTP transaction and returns the response.
*
* @param HttpRequest $request
* @return HttpResponse
*/
public function getResponse(HttpRequest $request)
{
$uri = $request->getUrl();
$headers = $request->getHeaders();
$flatHeaders = [];
foreach ($headers as $key => $value) {
$flatHeaders[] = $key . ": " . $value;
}
$flatHeaders[] = 'Connection: Keep-Alive';
$flatHeaders[] = 'Expect:';
$flatHeaders[] = 'Accept-Language: en-GB';
$flatHeaders[] = 'Cache-Control: no-cache';
$flatHeaders[] = 'User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)';
$curl = curl_init($uri);
curl_setopt($curl, CURLOPT_HEADER, false);
$payload = $request->getPayload();
switch ($request->getMethod()) {
case "head":
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "HEAD");
break;
case "delete":
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
break;
case "post":
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
break;
case "put":
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
break;
}
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, $flatHeaders);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
$responseCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
$httpResponse = new HttpResponse();
$httpResponse->setResponseBody($response);
$httpResponse->setResponseCode($responseCode);
return $httpResponse;
}
开发者ID:rhubarbphp,项目名称:rhubarb,代码行数:50,代码来源:CurlHttpClient.php
示例16: ajaxShutdown
function ajaxShutdown()
{
$isError = false;
if ($error = error_get_last()) {
switch ($error['type']) {
case E_ERROR:
case E_CORE_ERROR:
case E_COMPILE_ERROR:
case E_USER_ERROR:
case E_PARSE:
$log_file = ini_get("error_log");
if (file_exists($log_file)) {
$number_of_characters_to_get = 5000;
$bf = new BigFile($log_file);
$text = $bf->getFromEnd($number_of_characters_to_get);
$lines = array_reverse(explode("\n", $text));
$backtrace = "";
foreach ($lines as $i => $line) {
if (strstr($line, "Fatal")) {
for ($j = $i; $j > 0; $j--) {
$backtrace .= $lines[$j] . "\n";
}
break;
}
}
if ($backtrace == "") {
$backtrace = "No Fatal error found in the last {$number_of_characters_to_get} lines of {$log_file}";
}
} else {
$backtrace = "No error log found at " . $log_file;
}
$isError = true;
break;
}
}
if ($isError) {
send_http_error(new Exception("E_ERROR " . $error['message'] . "\n file: " . $error['file'] . " (" . $error['line'] . ")", E_FATAL_ERROR), "FATAL ERROR. shutdown function tried to restore backtrace from php error log ({$log_file}):\n" . $backtrace, true);
$response = new HttpResponse();
$response->setStatus("400 Bad Request");
$response->write("E_ERROR " . $error['message'] . "\n file: " . $error['file'] . " (" . $error['line'] . ")");
$response->flush();
}
}
开发者ID:rolwi,项目名称:koala,代码行数:43,代码来源:Ajax.extension.php
示例17: configureCurl
/**
* @param \Blar\Curl\Curl $curl Curl.
* @param \Blar\Http\HttpResponse $response Response.
* @return $this
*/
protected function configureCurl(Curl $curl, HttpResponse $response)
{
$curl->setMethod($this->getMethod());
$curl->setUrl($this->getUrl());
if ($this->getHeaders()) {
$headers = $this->createHeadersArray($this->getHeaders());
$curl->setOption(CURLOPT_HTTPHEADER, $headers);
}
if ($this->getBody()) {
$curl->setBody($this->getBody());
}
$curl->setHeaderCallback(function ($header) use($response) {
$response->setHeaderLine($header);
});
$curl->setWriteCallback(function ($part) use($response) {
$response->addBodyPart($part);
});
return $this;
}
开发者ID:blar,项目名称:http,代码行数:24,代码来源:HttpRequest.php
示例18: threadmain
function threadmain()
{
// Read request block
$buf = "";
while (true) {
$rl = socket_read($this->sock, 4096, PHP_BINARY_READ);
if (false == $rl) {
socket_close($this->sock);
return;
} else {
$buf = $buf . $rl;
}
if (strpos($buf, "\r\n\r\n")) {
break;
} else {
console::writeLn('%s', $buf);
}
}
$db = explode("\r\n\r\n", $buf);
$data = $db[0];
// Put back the rest of the buffer for posts etc
$buf = join('', array_slice($db, 1));
$request = new HttpRequest($data);
// data
$response = new HttpResponse();
// Pop the header off the buffer
$status = call_user_func_array($this->handler, array(&$request, &$response));
if ($status == 0) {
$status = 200;
}
$peer = "";
$port = 0;
socket_getpeername($this->sock, $peer, $port);
console::writeLn("%s %s:%d %d %s", $request->getMethod(), $peer, $port, $status, $request->getUri());
$response->writeHeaders($this->sock, 200);
$response->writeContent($this->sock);
socket_shutdown($this->sock, 2);
usleep(50000);
socket_close($this->sock);
}
开发者ID:noccy80,项目名称:lepton-ng,代码行数:40,代码来源:http.php
示例19: send
/**
* Sends a request
*
* @param peer.http.HttpRequest request
* @param int timeout default 60
* @param float connecttimeout default 2.0
* @return peer.http.HttpResponse response object
*/
public function send(HttpRequest $request, $timeout = 60, $connecttimeout = 2.0)
{
// Use proxy socket and Modify target if a proxy is to be used for this request,
// a proxy wants "GET http://example.com/ HTTP/X.X"
if ($this->proxy && !$this->proxy->isExcluded($url = $request->getUrl())) {
$request->setTarget(sprintf('%s://%s%s%s', $url->getScheme(), $url->getHost(), $url->getPort() ? ':' . $url->getPort() : '', $url->getPath('/')));
$s = $this->proxySocket;
} else {
$s = $this->socket;
}
// Socket still open from last request. This is the case when unread
// data is left on the socket (by not reading the body, e.g.), so do
// it the quick & dirty way: Close and reopen!
$s->isConnected() && $s->close();
$s->setTimeout($timeout);
$s->connect($connecttimeout);
$s->write($request->getRequestString());
$this->cat && $this->cat->info('>>>', $request->getHeaderString());
$response = new HttpResponse(new SocketInputStream($s));
$this->cat && $this->cat->info('<<<', $response->getHeaderString());
return $response;
}
开发者ID:melogamepay,项目名称:xp-framework,代码行数:30,代码来源:SocketHttpTransport.class.php
示例20: 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;
}
开发者ID:hyancat,项目名称:aliyun-direct-mail,代码行数:38,代码来源:HttpHelper.php
注:本文中的HttpResponse类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论