php post xml 到服务器 以及服务器如何接受(服务器间通过xml通讯)

来源:互联网 发布:php import 编辑:程序博客网 时间:2024/05/22 14:05

A服务器上 生成xml,并模拟post请求到B服务器,其中红色的部分根据自身服务器实际情况调整,下面是直接请求本地(B服务器)的index.php文件


$req = '<?xml version="1.0"?>
<INFO>
        <InfoType>TESTINFO</InfoType>
        <Version>1.0</Version>
        <UserName>TEST</UserName>
        <UserPwd>TEST</UserPwd>
</INFO>';

$header = "POST /index.php HTTP/1.0\r\n";
$header.= "Content-Type: text/xml\r\n";
$header.= "Content-Length: " . strlen($req) ."\r\n\r\n";
$fp        = fsockopen("localhost", 80, $errno, $errstr, 30);
fputs($fp, $header .$req);

while ( ! feof ( $fp ) )
{
    $res = fgets ( $fp, 1024 );
    var_dump($res).'<br />';

}


在index.php文件中 接受post过来的xml数据

echo $HTTP_RAW_POST_DATA  其中 $HTTP_RAW_POST_DATA 即为post过来的数据


原创粉丝点击