当前位置: 首页>>代码示例>>PHP>>正文


PHP HttpResponse类代码示例

本文整理汇总了PHP中HttpResponse的典型用法代码示例。如果您正苦于以下问题:PHP HttpResponse类的具体用法?PHP HttpResponse怎么用?PHP HttpResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了HttpResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的HttpResponse类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。