47 $pos = strpos($req,
'://');
48 $this->_protocol = strtolower(substr($req, 0, $pos));
50 $req = substr($req, $pos+3);
51 $pos = strpos($req,
'/');
52 if($pos ===
false) $pos = strlen($req);
53 $host = substr($req, 0, $pos);
55 if(strpos($host,
':') !==
false)
57 list($this->_host, $this->_port) = explode(
':', $host);
62 $this->_port = ($this->_protocol ==
'https') ? 443 : 80;
65 $this->_uri = substr($req, $pos);
66 if($this->_uri ==
'') $this->_uri =
'/';
82 $req =
'GET ' . $this->_uri .
' HTTP/1.0' . $crlf
83 .
'Host: ' . $this->_host . $crlf
87 $this->_fp = fsockopen(($this->_protocol ==
'https' ?
'ssl://' :
'') . $this->_host, $this->_port);
88 fwrite($this->_fp, $req);
89 while(is_resource($this->_fp) && $this->_fp && !feof($this->_fp))
91 $response .= fread($this->_fp, 1024);
96 $pos = strpos($response, $crlf . $crlf);
97 if($pos ===
false)
return($response);
98 $header = substr($response, 0, $pos);
99 $body = substr($response, $pos + 2 * strlen($crlf));
103 $lines = explode($crlf, $header);
104 foreach($lines as $line)
106 if(($pos = strpos($line,
':')) !==
false)
108 $headers[strtolower(trim(substr($line, 0, $pos)))] = trim(substr($line, $pos+1));
113 if(isset($headers[
'location']))
116 return($http->DownloadToString($http));