1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
function postSend($url,$vars){ $result = array(); $URL_parsed = parse_url($url) ; $host = $URL_parsed["host"]; $port = ($URL_parsed["port"]) ? $URL_parsed["port"] : 80; $path = $URL_parsed["path"]; $request.="POST ".$path." HTTP/1.1\r\n"; $request.="Host: ".$host.":".$port."\r\n"; $request.="Referer: $referer\r\n"; $request.="Content-type: application/x-www-form-urlencoded\r\n"; $request.="Content-length: ".strlen($vars)."\r\n"; $request.="Connection: close\r\n"; $request.="\r\n"; $request.=$vars."\r\n"; $fp = fsockopen($host, $port, $errno, $errstr, 30); fputs($fp, $request); while(!feof($fp)) { $result[] .= fgets($fp, 1024); } fclose($fp); return $result[10]; } //실제루틴 $url = "http://www.cena.co.kr/postTest.php"; $vars = "testvar1=test1&testvar2=test2"; $result = postSend($url,$vars); if($result == "OK"){ echo "Server Return : OK" ; } |
요지는 http 소켓을 만들때 저런 형태로 만들어서 보낸다는 것이다.
간단한 소스이므로 설명은 생략하며, 서버측에서 OK라는 신호를 찍어줬다면 아래의 echo가 찍힐것이다.
]]>
댓글 남기기