コード例 #1
0
ファイル: httprequest.php プロジェクト: ASDAFF/open_bx
 public function getHttpHost($raw = true)
 {
     if ($raw) {
         return $this->server->getHttpHost();
     }
     static $host = null;
     if ($host === null) {
         //scheme can be anything, it's used only for parsing
         $scheme = "http://";
         $host = $this->server->getHttpHost();
         $url = new Web\Uri($scheme . $host);
         $host = $url->getHost();
         $host = trim($host, "\t\r\n .");
     }
     return $host;
 }
コード例 #2
0
ファイル: httpclient.php プロジェクト: ASDAFF/open_bx
 protected function sendRequest($method, Uri $url, $postData = null)
 {
     $this->status = 0;
     $this->result = '';
     $this->responseHeaders->clear();
     $this->responseCookies->clear();
     if ($this->proxyHost != '') {
         $path = $url->getUrl();
         if ($this->proxyUser != '') {
             $this->setHeader("Proxy-Authorization", "Basic " . base64_encode($this->proxyUser . ":" . $this->proxyPassword));
         }
     } else {
         $path = $url->getPathQuery();
     }
     $request = $method . " " . $path . " HTTP/" . $this->version . "\r\n";
     $this->setHeader("Host", $url->getHost());
     $this->setHeader("Connection", "close", false);
     $this->setHeader("Accept", "*/*", false);
     $this->setHeader("Accept-Language", "en", false);
     if (($user = $url->getUser()) != '') {
         $this->setAuthorization($user, $url->getPass());
     }
     $cookies = $this->requestCookies->toString();
     if ($cookies != '') {
         $this->setHeader("Cookie", $cookies);
     }
     if ($this->compress) {
         $this->setHeader("Accept-Encoding", "gzip");
     }
     if (!is_resource($postData) && ($method == self::HTTP_POST || $method == self::HTTP_PUT)) {
         if ($this->requestHeaders->get("Content-Type") === null) {
             $contentType = "application/x-www-form-urlencoded";
             if ($this->requestCharset != '') {
                 $contentType .= "; charset=" . $this->requestCharset;
             }
             $this->setHeader("Content-Type", $contentType);
         }
         if ($this->requestHeaders->get("Content-Length") === null) {
             $this->setHeader("Content-Length", String::getBinaryLength($postData));
         }
     }
     $request .= $this->requestHeaders->toString();
     $request .= "\r\n";
     $this->send($request);
     if ($method == self::HTTP_POST || $method == self::HTTP_PUT) {
         if (is_resource($postData)) {
             //PUT data can be file resource
             while (!feof($postData)) {
                 $this->send(fread($postData, self::BUF_POST_LEN));
             }
         } else {
             $this->send($postData);
         }
         $this->send("\r\n");
     }
 }