mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-09 19:51:42 +09:00
PHP6에서 magic_quotes_gpc 함수 사용안하도록 수정 git-svn-id: http://xe-core.googlecode.com/svn/sandbox@4472 201d5d3c-b55e-5fd7-737f-ddc643e51545
81 lines
1.7 KiB
PHP
81 lines
1.7 KiB
PHP
<?php
|
|
/**
|
|
* @class HttpRequest
|
|
* @author haneul (haneul@gmail.com)
|
|
* @version 0.1
|
|
* @brief 다른 서버에 HTTP Request를 전송하고 result를 받아오는 클래스
|
|
* @remarks Connection: keep-alive 는 지원하지 않음
|
|
*/
|
|
|
|
class XEHttpRequest {
|
|
|
|
/// target host
|
|
var $m_host;
|
|
/// target Port
|
|
var $m_port;
|
|
/// header array
|
|
var $m_headers;
|
|
|
|
/**
|
|
* @brief Constructor
|
|
*/
|
|
function XEHttpRequest($host, $port)
|
|
{
|
|
$this->m_host = $host;
|
|
$this->m_port = $port;
|
|
$this->m_headers = array();
|
|
}
|
|
|
|
/**
|
|
* @brief Add (key, value) pair to the HTTP request header
|
|
*/
|
|
function AddToHeader($key, $value)
|
|
{
|
|
$this->m_headers[$key] = $value;
|
|
}
|
|
|
|
/**
|
|
* @brief send HTTP message to the host
|
|
* @return (result code, response body)
|
|
*/
|
|
function Send($target, $method="GET", $timeout = 3)
|
|
{
|
|
$socket = @fsockopen($this->m_host, $this->m_port, $errno, $errstr, $timeout);
|
|
if(!$socket)
|
|
{
|
|
return new Object(-1, "socket_connect_failed");
|
|
}
|
|
|
|
$this->AddToHeader('Host', $this->m_host);
|
|
$this->AddToHeader('Connection', "close");
|
|
|
|
$crlf = "\r\n";
|
|
$request = "$method $target HTTP/1.1$crlf";
|
|
|
|
foreach($this->m_headers as $equiv => $content)
|
|
{
|
|
$request .= "$equiv: $content$crlf";
|
|
}
|
|
$request .= $crlf;
|
|
fwrite($socket, $request);
|
|
|
|
list($httpver, $code, $status) = split(' +', rtrim(fgets($socket)));
|
|
// read response header
|
|
while(strlen(trim($line = fgets($socket))))
|
|
{
|
|
list($equiv, $content) = split(' *: *', rtrim($line));
|
|
}
|
|
$body = '';
|
|
while(!feof($socket))
|
|
{
|
|
$body .= fgets($socket, 128);
|
|
}
|
|
fclose($socket);
|
|
|
|
$ret->result_code = $code;
|
|
$ret->body = $body;
|
|
|
|
return $ret;
|
|
}
|
|
}
|
|
?>
|