0
 http = Net::HTTP.new('rty.makemytrip.com', 80)
   http.use_ssl = false
   path="http://rty.makemytrip.com/btd_Webs_CreateIncident/MMT_Webs_CreateIncident.asmx?op=CreateIncident"
# Create the SOAP Envelope
data = <<-EOF
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
  SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP:Body>
    <CreateIncident xmlns="http://MakeMyTrip.org/">
      <FirstName>#{params[:name]}</FirstName>
      <Email>#{params[:email]}</Email>
      <CityOfResidence>#{params[:city]}</CityOfResidence>
      <MobilePhone>#{params[:mobile]}</MobilePhone>
    </CreateIncident>
  </SOAP:Body>
</SOAP-ENV:Envelope>
EOF
# Set Headers
headers = {
  'Content-Type' => 'Content-Type: application/soap+xml; charset=utf-8'
}
# Post the request
resp, data = http.post(path, data, headers)
# Output the results
logger.error "code  = >>>>>>>>#{resp.code}"
logger.error "Response message = >>>>>>>>Message =#{resp.message}"
resp.each { |key, val|
  logger.error  "key>#{key}>>>>>#{val}"
}
logger.error "data>>>>>#{ data}"

它给了我们这个错误

code  = >>>>>>>>500
Response message = >>>>>>>>Message =Internal Server Error
key>x-powered-by>>>>>ASP.NET
key>x-aspnet-version>>>>>2.0.50727
key>connection>>>>>close
key>content-type>>>>>text/xml; charset=utf-8
key>date>>>>>Thu, 19 Sep 2013 08:35:13 GMT
key>server>>>>>Microsoft-IIS/7.5
key>content-length>>>>>442
key>cache-control>>>>>private
data>>>>>
   <?xml version="1.0" encoding="utf-8"?>
   <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
     <soap:Body>
       <soap:Fault>
         <faultcode>soap:Server</faultcode>
         <faultstring>Server was unable to process request. ---&gt; 'SOAP' is an undeclared namespace. Line 8, position 5.</faultstring>
         <detail />
       </soap:Fault>
     </soap:Body>
   </soap:Envelope>

这段代码有什么问题

4

1 回答 1

1

错误是它在您的请求中'SOAP' is an undeclared namespace. Line 8, position 5.抱怨此字符串,因为未声明命名空间。<SOAP:Body>SOAP

因此,您声明SOAP-ENV为命名空间http://schemas.xmlsoap.org/soap/envelope/,我认为应该将其更改为<SOAP-ENV:Body>. 并且不要忘记也更改</SOAP:Body></SOAP-ENV:Body>

于 2013-09-19T08:46:08.113 回答