使用 file_get_contents() 接收 XML
我是这个网站的新手,也是网络服务的新手。我正在尝试创建一个 Web 服务,将 xml 响应发送回客户端请求。我遇到的问题是当我执行客户端请求时,浏览器挂起并最终返回服务器超时错误。我已检查 PHP.INI 设置以确保allow_url_fopen 设置为打开。 我使用 Zend Server 在 IBM i 上托管该网站。 预先感谢您的帮助。
这就是我尝试执行此操作的方式:
服务器端:此文件称为 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);
I am new to this site and also new to web services. I am trying to create a web service that sends an xml response back to a client request. The problem I am having is when I execute the client request, the browser hangs and eventually comes back with a server time out error. I have checked the PHP.INI settings to make sure allow_url_fopen is set to on.
I am hosting the website on an IBM i using Zend Server.
Thanks in advance for your help.
This is how I am trying to do it:
Server side: This file is called 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();
?>
Client side:
<?php
$xml = file_get_contents('http://corvetteamericadealers.com/dev1/Examples/XML3.php');
$sxe = new SimpleXMLElement($xml);
var_dump($sxe);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这段代码对我来说效果很好。检查一下。
这是我的输出。
This code works fine for me. Just check.
And this is my output.
您正在通过解析soap xml 来实现Web 服务吗?使用某种 Web 服务机制从 .wsdl 文件生成类。
You are implementing web service by parsing soap xml? Use some web service mechanism for generate classes from .wsdl file.