gpt4 book ai didi

ruby - SOAP + SSL + Ruby Savon - HTTPClient::ConnectTimeoutError:执行已过期

转载 作者:太空宇宙 更新时间:2023-11-03 16:37:19 24 4
gpt4 key购买 nike

我正在尝试获取一个简单的 ruby​​ 脚本来向 SOAP API 发送请求,但我无法获得响应。

这就是我想要做的:

require 'date'
require 'savon'

# Create the client
client = Savon::Client.new do
wsdl.document = File.expand_path("path to wsdl document", __FILE__)
end

# Setup namespaces and credentials
client.wsdl.namespace = "http://www.example.com"
client.wsse.credentials "[USERNAME]", "[PASSWORD]"

# Setup ssl configuration
client.http.auth.ssl.cert_key_file = "path to key pem file"
client.http.auth.ssl.cert_file = "path to cert pem file"
client.http.auth.ssl.verify_mode=:peer

# execute request
response = client.request :sub, :get_data do
soap.body = {"sub:id" => "123456"}
end

这个请求结束于:

D, [2011-05-05T10:21:45.014588 #22136] DEBUG -- : SOAP request: "http://www.example.com"
D, [2011-05-05T10:21:45.014743 #22136] DEBUG -- : Content-Type: text/xml;charset=UTF-8, SOAPAction: "getData"
D, [2011-05-05T10:21:45.014787 #22136] DEBUG -- : <?xml version="1.0" encoding="UTF-8"?><env:Envelope ...(XML request)... </env:Body></env:Envelope>
D, [2011-05-05T10:21:45.014864 #22136] DEBUG -- : HTTPI executes HTTP POST using the httpclient adapter
HTTPClient::ConnectTimeoutError: execution expired

但是,当我尝试通过 curl 发送相同的请求时,它起作用了(将上面的 xml 请求复制到 soap-request.xml 文件):

curl -k -v --header "Content-Type: text/xml;charset=UTF-8, SOAPAction: 'getData'" https://www.example.com -d@soap-request.xml --cert-type PEM --cert path_to_pem_file_with_both_key_and_cert

关于我在 ruby​​ 脚本中遗漏了什么有什么想法吗?

提前致谢。

更新:

如果 WSDL 文档是正确的,上面的代码就可以工作。但是,如果没有或错误,只需将客户端声明替换为:

# Create the client
client = Savon::Client.new do
wsdl.endpoint = "https://whateverendpoint.com"
wsdl.namespace = "http://whatevernamespace.com"
end

最后,如 Savon 的文档中所述,捕获可能的错误也是一个好主意:

begin
# execute request
response = client.request :sub, :get_data do
soap.body = {"sub:id" => "123456"}
end
rescue Savon::SOAP::Fault => fault
puts fault.to_s
end

最佳答案

您是否尝试过延长 http 超时?我的一些 SOAP 调用也遇到了同样的问题,这些调用在服务器端花费了很长时间。我做的是这个

jira = Savon::Client.new do
wsdl.document = 'http://jira.xxx.com/rpc/soap/jirasoapservice-v2?wsdl'
end

jira.http.read_timeout = 300

done = 0
dotPrinter = Thread.new do
sec = 0
while(done==0) do
sleep 1
$STDERR.print "\b\b\b%03i" % sec
sec += 1
end
end

resp = jira.request :get_issues_from_filter do
soap.body = {:in0 => jira_token, :in1 => 18579}
end
done = 1

关于ruby - SOAP + SSL + Ruby Savon - HTTPClient::ConnectTimeoutError:执行已过期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5896653/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com