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


PHP URLUtil::resolve方法代码示例

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


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

示例1: send

 /**
  * Sends a request to a HTTP server, and returns a response.
  *
  * @param RequestInterface $request
  * @return ResponseInterface
  */
 function send(RequestInterface $request)
 {
     $this->emit('beforeRequest', [$request]);
     $retryCount = 0;
     $redirects = 0;
     do {
         $doRedirect = false;
         $retry = false;
         try {
             $response = $this->doRequest($request);
             $code = (int) $response->getStatus();
             // We are doing in-PHP redirects, because curl's
             // FOLLOW_LOCATION throws errors when PHP is configured with
             // open_basedir.
             //
             // https://github.com/fruux/sabre-http/issues/12
             if (in_array($code, [301, 302, 307, 308]) && $redirects < $this->maxRedirects) {
                 $oldLocation = $request->getUrl();
                 // Creating a new instance of the request object.
                 $request = clone $request;
                 // Setting the new location
                 $request->setUrl(URLUtil::resolve($oldLocation, $response->getHeader('Location')));
                 $doRedirect = true;
                 $redirects++;
             }
             // This was a HTTP error
             if ($code >= 400) {
                 $this->emit('error', [$request, $response, &$retry, $retryCount]);
                 $this->emit('error:' . $code, [$request, $response, &$retry, $retryCount]);
             }
         } catch (ClientException $e) {
             $this->emit('exception', [$request, $e, &$retry, $retryCount]);
             // If retry was still set to false, it means no event handler
             // dealt with the problem. In this case we just re-throw the
             // exception.
             if (!$retry) {
                 throw $e;
             }
         }
         if ($retry) {
             $retryCount++;
         }
     } while ($retry || $doRedirect);
     $this->emit('afterRequest', [$request, $response]);
     if ($this->throwExceptions && $code >= 400) {
         throw new ClientHttpException($response);
     }
     return $response;
 }
开发者ID:samj1912,项目名称:repo,代码行数:55,代码来源:Client.php


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