Ruby 和 Savon 错误 : POST method not supported by this URL

标签 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" => "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7d1b12123d1f1c0f531e1210" rel="noreferrer noopener nofollow">[email protected]</a>",
                        "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><a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8ee8e1e1ceeceffca0ede1e3" rel="noreferrer noopener nofollow">[email protected]</a></urn1:email>
                <urn1:password>foobar123</urn1:password>
                <urn1:account>12345</urn1:account>
             </urn:passport>
          </urn:login>
       </soapenv:Body>
    </soapenv:Envelope>

谢谢

最佳答案

你的代码几乎是正确的。我更改了 SOAP 端点,在请求 block 中指定了 urn1 命名空间,并将 SOAP 操作从请求主体哈希移至请求方法。

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" => "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f1979e9eb1939083df929e9c" rel="noreferrer noopener nofollow">[email protected]</a>",
      "urn1:password" => "foobar123",
      "urn1:account" => "12345"
    }
  }
end

希望有帮助!

干杯,
丹尼尔

关于Ruby 和 Savon 错误 : POST method not supported by this URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9423568/

相关文章:

java - 在基于 JAX-WS 的应用程序上启用 HTTP OPTIONS 方法

c++ - 使用 libcurl 编写 HTTPS SOAP 客户端

rest - 文件转换服务的有效 REST 方法是什么?

php - SOAP WSDL 关联数组

ruby - 在 Chef 中,为什么没有挽救引发的异常?

ruby - 是否有任何用于 Windows 和 Unix 的远程脚本编写的框架?

java - JAXB2 Maven Plugin xjc parse error : org. xml.sax.SAXParseException: Unexpected <xs:element>出现

c# - 在 Powershell 中创建一个 ScheduleDefinition 对象

Ruby:奇怪地使用 "?"运算符比较字符串是否相等

ruby - rspec 测试 ruby​​ 方法是否返回数组