问题描述:

I'm trying to call a web service from a PHP page via a Ruby script. The PHP script returns a string and itself calls another web service; I've tested the PHP script alone and it returns a single string. I'm trying to call this method via RPC using the following code:

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

I get this result back:

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

However when I run the PHP code itself (and give it a real value, obviously) it doesn't throw any errors at all and returns the expected value. It's just not working with Ruby and REXML; how can I fix this? The web service that the PHP script is calling is by a third-party and I cannot modify the response, but obviously the response is working fine in PHP but REXML has an issue with it.

网友答案:

Without the xml that is returned it's hard to say. Have you tried using an xml validation tool like: xmlstarlet, xmllint, or tidy.

These tools will tell you if your xml is well formed. If it's not well formed then it depends on what's wrong with it as to how you can fix it.

Post more details for a better answer.

相关阅读:
Top