我正在尝试通过 Ruby 脚本从 PHP 页面调用 Web 服务。PHP 脚本返回一个字符串,它本身调用另一个 Web 服务;我已经单独测试了 PHP 脚本,它返回一个字符串。我正在尝试使用以下代码通过 RPC 调用此方法:
require 'soap/rpc/driver'
driver = SOAP::RPC:Driver.new('http://mysite.com/services/webservices.php', 'urn:mysite')
driver.add_method('getMobileCarrier', 'phoneNumber')
driver.getMobileCarrier('15551234567') # fake number, obviously
我得到了这个结果:
REXML::ParseException: malformed XML: missing tag start
Line:
Position:
Last 80 unconsumed characters:
< in <b>/var/www/html/services/webservices.php</b>
from /opt/local/lib/ruby/1.8/rexml/parsers/baseparser.rb:356:in `pull'
from /opt/local/lib/ruby/1.8/rexml/parsers/streamparser.rb:16:in `parse'
from /opt/local/lib/ruby/1.8/rexml/document.rb:201:in `parse_stream'
from /opt/local/lib/ruby/1.8/xsd/xmlparser/rexmlparser.rb:27:in `do_parse'
from /opt/local/lib/ruby/1.8/soap/parser.rb:92:in `parse'
from /opt/local/lib/ruby/1.8/soap/processor.rb:39:in `unmarshal'
from /opt/local/lib/ruby/1.8/soap/rpc/proxy.rb:236:in `unmarshal'
from /opt/local/lib/ruby/1.8/soap/rpc/proxy.rb:175:in `route'
from /opt/local/lib/ruby/1.8/soap/rpc/proxy.rb:141:in `call'
from /opt/local/lib/ruby/1.8/soap/rpc/driver.rb:178:in `call'
from /opt/local/lib/ruby/1.8/soap/rpc/driver.rb:232:in `getMobileCarrier'
from (irb):4
但是,当我运行 PHP 代码本身时(显然,给它一个实际值)它根本不会抛出任何错误并返回预期值。它只是不适用于 Ruby 和 REXML;我怎样才能解决这个问题?PHP 脚本调用的 Web 服务是由第三方提供的,我无法修改响应,但显然响应在 PHP 中运行良好,但 REXML 存在问题。