php - CodeIgniter Web 服务客户端

标签 php xml web-services codeigniter soap

我是 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 (我假设)。

  1. 检查 Soap,soap 扩展程序已加载到您的服务器上
  2. 了解 SoapClient http://php.net/manual/en/class.soapclient.php
  3. 查看该网络服务是否提供 WSDL(网络服务描述语言)文件。
  4. 使用 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/

相关文章:

c++ - 将现有的 C++ Web 服务转换为负载平衡服务器?

php - 为什么我在使用命名参数时会看到 "invalid parameter number"错误?

php - Doctrine2 无法通过关系加载具有命名空间的类

javascript - 检查表单中的多个 div,如果 div 没有指定的类,则发出警报并阻止提交

java - 安卓.view.InflateException : Binary XML file line #: Error inflating class

android - 如何在android Lollipop的xml中添加RecyclerView

c# - XmlSerializer 不使用在类上定义的 XmlRoot

web-services - REST API 设计 : linking resources

基于php的成员(member)框架

c# - WCF 传输与证书问题的 https 通信