我是 CI 的新手,我想从 Web 服务 WebLogic 检索 XML 数据,服务器位于:http://services.insw.go.id/web-services/nsw?operation.invoke=getListGA .我想从服务器获取 XML 响应。我应该怎么做?
我在 Controller (resttest.php)上实现了这个功能
public function getRest()
{
$this->rest->initialize(array('server' => 'http://services.insw.go.id'));
$lartas = $this->rest->get('web-services/nsw',array('operation.invoke' => 'getListGA'),'xml');
die(var_dump($lartas));
}
有时我会收到类似“array(0) { }”的错误,如果我刷新,我会看到所有 HTML View ,就像我浏览到:http://services.insw.go.id/web-services/nsw?operation.invoke=getListGA 时一样。
我是不是错了,或者遗漏了某些步骤,或者您对如何更改此代码有什么建议吗?
最佳答案
看起来您的网络服务正在使用 SOAP(简单对象访问协议(protocol))。这不是 REST。您需要将 PHP 的内置 Soap 扩展与 SoapClient 类一起使用。通过这种方式,可以很容易地将 XML“请求”发布到该页面,该页面将返回 xml 结果而不是 html View (我假设)。
- 检查 Soap,soap 扩展程序已加载到您的服务器上
- 了解 SoapClient http://php.net/manual/en/class.soapclient.php
- 查看该网络服务是否提供 WSDL(网络服务描述语言)文件。
- 使用 wsdl 创建一个 soap 客户端的实例并调用您需要的函数。
来自 PHP.net 的简单示例
$client = new SoapClient("http://localhost/code/soap.wsdl");
$something = $client->HelloWorld(array());
echo $something->HelloWorldResult;
关于php - CodeIgniter Web 服务客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14954918/