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. ---> 'SOAP' is an undeclared namespace. Line 8, position 5.</faultstring>
<detail />
</soap:Fault>
</soap:Body>
</soap:Envelope>
此代码有什么问题
答案 0 :(得分: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>
。