我是这个网站的新手,也是web服务的新手。我正在尝试创建一个Web服务,将xml响应发送回客户端请求。我遇到的问题是当我执行客户端请求时,浏览器挂起,并最终返回服务器超时错误。我检查了PHP.INI设置,确保allow_url_fopen设置为打开。 我在使用Zend Server的IBM i上托管网站。 在此先感谢您的帮助。用file_get_contents()接收XML
这是我正在试图做到这一点:
服务器端:此文件被称为XML3.php
<?php
ob_start();
header("Content-Type:text/xml");
echo "<?xml version='1.0' encoding='UTF-8' ?>";
echo '<posts>';
echo '<post>';
echo "<title>title1</title>";
echo "<body>this is the body</body>";
echo "<post_date>02/10/2012</post_date>";
echo '</post>';
echo '</posts>';
ob_end_flush();
?>
客户端:
<?php
$xml = file_get_contents('http://corvetteamericadealers.com/dev1/Examples/XML3.php');
$sxe = new SimpleXMLElement($xml);
var_dump($sxe);
做'new SimpleXMLElement($ url,0,true);'。并且也不需要输出缓冲。 – Gordon 2012-02-13 13:55:58