Ruby和Savon错误:此URL不支持POST方法

时间:2012-02-24 00:20:43

标签: ruby soap wsdl savon

我是savon和SOAP的新手。

我正在尝试创建对netsuite wsdl服务的请求。当我运行它时,我收到以下错误:

    D, [2012-02-23T15:05:08.714815 #2284] DEBUG -- : HTTPI executes HTTP POST using the httpclient adapter
    D, [2012-02-23T15:05:19.670815 #2284] DEBUG -- : SOAP response (status 405):
    c:/Ruby187/lib/ruby/gems/1.8/gems/savon-0.9.9/lib/savon/soap/response.rb:107:in 
    `raise_errors': HTTP error (405): HTTP method POST is not supported by this URL 
    (Savon::HTTP::Error)

似乎我需要使用get而不是post,但我无法弄清楚如何将请求设置为get。任何帮助,将不胜感激。

    client = Savon::Client.new do
      wsdl.endpoint = "https://webservices.netsuite.com/wsdl/v2011_2_0"
      wsdl.namespace = "urn:messages_2011_2.platform.webservices.netsuite.com"
      wsdl.namespace = "urn:core_2011_2.platform.webservices.netsuite.com"
    end

    response = client.request(:body ) do
      soap.element_form_default = :qualified
      soap.body = {"urn:login" =>
                    {
                      "urn:passport" =>
                      {
                        "urnl:email" => "foo@bar.com",
                        "urnl:password" => "foobar123",
                        "urnl:account" => "12345"
                      }
                    }
                  }
    end
下面的

是SOAPUi中的soap请求

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"         xmlns:urn="urn:messages_2011_2.platform.webservices.netsuite.com"                         xmlns:urn1="urn:core_2011_2.platform.webservices.netsuite.com">
       <soapenv:Header>
          <urn:partnerInfo>      </urn:partnerInfo>
          <urn:applicationInfo>       </urn:applicationInfo>
       </soapenv:Header>
       <soapenv:Body>
          <urn:login>
             <urn:passport>
                <urn1:email>foo@bar.com</urn1:email>
                <urn1:password>foobar123</urn1:password>
                <urn1:account>12345</urn1:account>
             </urn:passport>
          </urn:login>
       </soapenv:Body>
    </soapenv:Envelope>

感谢

1 个答案:

答案 0 :(得分:3)

你的代码几乎是正确的。我更改了SOAP端点,在请求块中指定了urn1名称空间,并将SOAP操作从请求主体Hash移动到请求方法。

client = Savon::Client.new do
  wsdl.endpoint = "https://webservices.netsuite.com/services/NetSuitePort_2011_2"
  wsdl.namespace = "urn:messages_2011_2.platform.webservices.netsuite.com"
end

response = client.request(:urn, :login) do
  soap.namespaces["xmlns:urn1"] = "urn:core_2011_2.platform.webservices.netsuite.com"
  soap.body = {
    "urn1:passport" => {
      "urn1:email" => "foo@bar.com",
      "urn1:password" => "foobar123",
      "urn1:account" => "12345"
    }
  }
end

希望有所帮助!

干杯,
丹尼尔