2016-01-24 57 views
0

我想使用此WSDL http://www.webservicex.net/uszip.asmx?WSDL使用net/http的GetInfoByZIP服務器,但始終得到錯誤「服務器無法識別HTTP頭SOAPAction的值」服務器無法識別HTTP頭SOAPAction的值與淨/ http

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

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' }) 
+0

完美!作品!!謝謝 – Angel

+0

@Angel - 如果它解決了問題,那麼我會很感激你給我的信用,將答案標記爲「接受」。非常感謝。 :) – Roberto

相關問題