본문 바로가기
프로그래밍/PHP

PHP 소켓 POST로.. XML 값

by 백룡화검 2009. 4. 14.
$fileHost = "URL";
$filePath = "나머지주소";
$port = 포트번호;
$param = "a=11&b=22&c=33"; //넘길값
$len = strlen($param);  //길이

$fp = fsockopen ($fileHost, $port, $errno, $errstr, 30);

if ($fp) {
    
    fputs($fp,"POST $filePath HTTP/1.1\n");
    fputs($fp,"Host: $fileHost\n");
    fputs($fp,"User-Agent: ".$_SERVER[HTTP_USER_AGENT]."\n");
    fputs($fp,"Content-type: application/x-www-form-urlencoded\n");
    fputs($fp,"Content-length: ".$len."\n");
    fputs($fp,"Connection: Close\r\n\r\n");
    fputs($fp,"$param");
    
    while (!feof($fp)){
     $data = $data.fgets($fp,4096);
    }
    
    //헤더 자르고 값만..
    $data = explode("\r\n\r\n",$data);
    
    //XML에서 값만.. (값 : $out[1][0]);
    preg_match_all("|<[^>]+>(.*)</[^>]+>|U",$data[2], $out, PREG_PATTERN_ORDER);

}else{
    echo "$errstr ($errno)<br>\n";
}
fclose ($fp);