2007.08.09 18:45

PHP - HTTP GET Request 구현

1. 개념
fsockopen 함수를 사용하여 구현한다.

2. 소스
DEFINE("CONTENT_TYPE", "multipart/form-data; boundary=");
DEFINE("CRLF", "\r\n");
DEFINE("CONTENT_DISPOSITION", "Content-Disposition: form-data; name=\"%s\"");
DEFINE("FILE_NAME_PLACE_HOLDER", "; filename=\"%s\"");
DEFINE("CONTENT_TYPE_PLACE_HOLDER", "Content-Type: %s\r\n\r\n");
DEFINE("CONTENT_LENGTH", "Content-Length: %d\r\n");
DEFINE("BOUNDARY", "---------------------------" . "020603111835686");

function http_form_get_send($host, $port, $url, $result_len)
                $headers = array(
                        "GET $url HTTP/1.0" . CRLF,
                        "Accept: */*" . CRLF,
                  "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)" . CRLF,
                  "Host: $host" . CRLF,
                  "Connection: Close" . CRLF,

                $sock = fsockopen($host, $port);

                // send headers
                for($i = 0;$i < count($headers);$i++) {
                        fputs($sock, $headers[$i]);
                // send end of header
                fputs($sock, CRLF);

                while(!feof($sock)) {
                        $s = fgets($sock, 1024);

                        if($s) {
                                // skip headers
                                if($s[0] == "\n" || $s[0] == "\r")
                        else break;

                $result = fread($sock, $result_len);


                return $result;                

3. 사용 예
$data = "?ownerid=blue";
$data .= "&ticket=5230315";
$data .= "&from=016";
$data .= "&to_number=016";
$data .= "&message=hohoho";

$result = http_form_get_send("ipager.test.co.kr", "80", "/sendsms/" . $data, 1024) ;

print "result : " . $result;

4. 소스파일

Trackback 0 Comment 1
  1. barato timberland 2012.12.25 12:30 address edit & del reply

    United claims that they are just doing what nearly eight other airlines have done, http://www.timberlandbaratas.com barato timberland. They are saying that this is for the comfort of other passengers. Representatives from United said that they had over 700 complaints from passengers who were made uncomfortable because the person next to them was a little too close for comfort.With the population of the United States growing larger, http://www.timberlandbaratas.com zapatos timberland, it would seem that many airline seats have gotten smaller, http://www.timberlandbaratas.com timberland niños. In an effort to pack as many passengers into a plane, http://www.timberlandbaratas.com timberland, coach seats are just a little over 17 inches. You can still find seats that are around 19 inches, http://www.timberlandbaratas.com Mujer Timberland, but most domestic carriers tend to have the 17 inch seats.Still, many opponents to this are just saying it, http://www.timberlandbaratas.com timberland españa?s another way for United to make money in a tough economy. They say that seats should be made to fit the population and that the seats just need to be made bigger.Learn more about airline industry news and controversies at blog.flyhub.Related articles:

    http://neoone.kr/category/頂勲攴鸽灅氚嶊磤霠�page=2 La mission de conseil juridique menée à Abidjan auprès de Laurent Gbagbo par les avocats fran

    http://bspfp.pe.kr/?page=4 Planning a trip to