gpt4 book ai didi

savon - 使用 Savon 对 Polarion 网络服务进行身份验证

转载 作者:行者123 更新时间:2023-12-04 05:15:33 24 4
gpt4 key购买 nike

我正在尝试关注讨论 here使用 Ruby 和 Savon。我能够检索 session ID,但是每当我执行来自需要身份验证(跟踪器)的客户端的请求时,我都会收到“授权失败”错误。

require 'Savon'

tracker_url = 'http://myserver/polarion/ws/services/TrackerWebService?wsdl'
session_url = 'http://myserver/polarion/ws/services/SessionWebService?wsdl'

# todo handle bad login credentials gracefully
session_client = Savon.client(wsdl: session_url)
response = session_client.call(:log_in, message: {user_name: 'lsimons', password: 'mypassword'})
session_id = response.header[:session_id]

puts "Session ID: #{session_id}"

tracker_client = Savon.client(wsdl: tracker_url, soap_header: {"session" => session_id}, headers: {"sessionID" => session_id})

puts "Requesting Workitem"
begin
tracker_client.call(:get_work_item_by_id, message: {project_id: 'myProject', workitem_id: 'myWorkitem'})
rescue
puts "Client call failed"
end

此代码为 tracker_client 创建以下 SOAP 请求:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ins0="http://ws.polarion.com/TrackerWebService-impl" xmlns:ins1="http://ws.polarion.com/types" xmlns:ins2="http://ws.polarion.com/TrackerWebService-types" xmlns:ins3="http://ws.polarion.com/ProjectWebService-types" xmlns:tns1="http://ws.polarion.com/TrackerWebService" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Header>
<session>2164640482421325916</session>
</env:Header>
<env:Body>
<tns1:getWorkItemById>
<ins0:projectId>myProject</ins0:projectId>
<ins0:workitemId>myWorkitem</ins0:workitemId>
</tns1:getWorkItemById>
</env:Body>
</env:Envelope>

但是,在论坛讨论中,sessionID 元素出现在标题之前。我不认为这在标准 SOAP 中是可能的?有没有办法通过 Savon 实现这一目标,还是我误解了论坛讨论?

最佳答案

我在同一个线程之后遇到了同样的问题。这就是我让它工作的方式(通过复制 log_in 请求的响应头):

tracker_client = Savon.client(
wsdl: tracker_url,
soap_header: {
"ns1:sessionID" => session_id,
:attributes! => {
"ns1:sessionID" => {
"env:actor" => "http://schemas.xmlsoap.org/soap/actor/next",
"env:mustUnderstand" => "0",
"xmlns:ns1" => "http://ws.polarion.com/session"
}
}
}
)

关于savon - 使用 Savon 对 Polarion 网络服务进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14320978/

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