我想使用net / http使用此WSDL http://www.webservicex.net/uszip.asmx?WSDL的GetInfoByZIP服务但总是得到错误"服务器无法识别HTTP Header SOAPAction"
的值path = '/uszip.asmx'
#http://www.webservicex.net/uszip.asmx?WSDL
# Create the SOAP Envelope
data = <<-EOF
<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>
<GetInfoByZIPResponse xmlns="http://www.webserviceX.NET">
<GetInfoByZIPResult>
<NewDataSet xmlns="">
<Table>
<CITY>Beverly Hills</CITY>
<STATE>CA</STATE>
<ZIP>90210</ZIP>
<AREA_CODE>310</AREA_CODE>
<TIME_ZONE>P</TIME_ZONE>
</Table>
</NewDataSet>
</GetInfoByZIPResult>
</GetInfoByZIPResponse>
</soap:Body>
</soap:Envelope>EOF
host = "www.webservicex.net"
http = Net::HTTP.new(host)
resp = http.post(path, data, { 'Content-Type' => 'text/xml; charset=utf-8', 'SOAPAction' => 'GetInfoByZIP' })
任何人都可以帮助我吗? 感谢
答案 0 :(得分:0)
soapAction似乎不正确。
尝试使用此处示例中指定的完整soapAction:
http://www.webservicex.net/uszip.asmx?op=GetInfoByZIP
POST /uszip.asmx HTTP/1.1
Host: www.webservicex.net
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.webserviceX.NET/GetInfoByZIP"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetInfoByZIP xmlns="http://www.webserviceX.NET">
<USZip>string</USZip>
</GetInfoByZIP>
</soap:Body>
</soap:Envelope>
按如下方式更改您的代码:
resp = http.post(path, data, { 'Content-Type' => 'text/xml; charset=utf-8', 'SOAPAction' => 'http://www.webserviceX.NET/GetInfoByZIP' })