示例#1
0
 /**
  * url forward 兼容处理
  * 获取真正的请求链接,并初始化socket句柄
  * 
  * @param array $options
  */
 private function followLocation()
 {
     if (!$this->_redirects) {
         return;
     }
     if ($this->_maxRedirs <= 0) {
         return;
     }
     $maxRedirs = $this->_maxRedirs;
     $newurl = $this->url;
     do {
         /* @var $socket WindHttpSocket */
         $socket = new WindHttpSocket($newurl, $this->timeout);
         $socket->setResponseHasBody(false);
         $socket->setResponseHasHeader(true);
         $header = $socket->send();
         $code = $socket->getStatus();
         $socket->close();
         if ($code == 301 || $code == 302) {
             preg_match('/Location:(.*?)\\n/', $header, $matches);
             $newurl = trim(array_pop($matches));
         } else {
             $code = 0;
         }
     } while ($code && --$maxRedirs);
     if ($newurl == $this->url) {
         return;
     }
     $this->url = $newurl;
     $this->httpHandler = $this->createHttpHandler();
 }