【问题标题】:Server did not recognize the value of HTTP Header SOAPAction with net/http服务器无法识别带有 net/http 的 HTTP Header SOAPAction 的值
【发布时间】:2016-04-30 17:20:52
【问题描述】:

我想通过 net/http 使用此 WSDL http://www.webservicex.net/uszip.asmx?WSDL 的 GetInfoByZIP 服务,但总是收到错误“服务器无法识别 HTTP 标头 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' })

谁能帮帮我? 谢谢

【问题讨论】:

    标签: ruby web-services soap wsdl net-http


    【解决方案1】:

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

    【讨论】:

    • 完美!!作品!!谢谢
    猜你喜欢
    • 2014-12-02
    • 2011-12-19
    • 1970-01-01
    • 2012-01-19
    • 2018-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-06
    相关资源
    最近更新 更多