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


PHP HttpResponse::setStatusCode方法代码示例

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


在下文中一共展示了HttpResponse::setStatusCode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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

示例2: send

 /**
  * Sends the response using the result
  * 
  * @param mixed $result Result
  * @return void
  */
 public function send($result = null)
 {
     if ($result instanceof HttpResponse) {
         $result->send();
         exit;
     }
     // Output the result
     if (!$result instanceof GenericResult) {
         $result = new SuccessResult($result);
     }
     $result = elgg_trigger_plugin_hook('result', 'graph', null, $result);
     $output = elgg_view('graph/output', array('result' => $result));
     if (elgg_get_viewtype() === 'default') {
         $layout = elgg_view_layout('one_column', array('content' => $output));
         $output = elgg_view_page('', $layout);
     }
     $this->response->setStatusCode($result->getStatusCode())->setContent($output)->prepare($this->request)->send();
     exit;
 }
开发者ID:hypejunction,项目名称:hypegraph,代码行数:25,代码来源:Router.php

示例3: testGetResponseStatusLineWithNonExistingHttpStatusCode

 /**
  * Test's the status line getter with a non existing http status code
  */
 public function testGetResponseStatusLineWithNonExistingHttpStatusCode()
 {
     $this->response->setStatusCode(999);
     $this->assertSame("HTTP/1.1 999 Unassigned\r\n", $this->response->getStatusLine());
 }
开发者ID:techdivision,项目名称:http,代码行数:8,代码来源:ResponseTest.php

示例4: testSetStatusCode

 /**
  * @covers \http\HttpResponse::setStatusCode
  */
 public function testSetStatusCode()
 {
     $this->object->setStatusCode(301);
     $code = $this->object->getStatusCode();
     $this->assertEquals(301, $code, 'Status code should be 301');
 }
开发者ID:elgervb,项目名称:php-http,代码行数:9,代码来源:HttpResponseTest.php


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