从 Initialize 方法设置 Savon 全局 headers 值
Set Savon global headers value from Initialize method
这是我的 BaseConsumer 模块,
module BaseConsumer
extend ActiveSupport::Concern
included do
extend Savon::Model
client endpoint: 'my end_point',
namespace: 'http://abc',
namespace_identifier: nil,
env_namespace: 's',
headers: {}
end
def initialize(client_id)
#I want to set here, client_id in headers value as a global option.
end
end
现在我想在全局 header 中设置一个值(比如 client_id)。我试过 soap_header
但它将 header 值设置为本地选项。我想在初始化时设置它。它浪费了我很多时间:(所以请帮忙。在此先感谢。
我已经解决了。我们可以轻松地将 headers 设置为全局选项。只需在 initialize
方法中编写以下代码.... :)
client.global.headers { options }
这是我的 BaseConsumer 模块,
module BaseConsumer
extend ActiveSupport::Concern
included do
extend Savon::Model
client endpoint: 'my end_point',
namespace: 'http://abc',
namespace_identifier: nil,
env_namespace: 's',
headers: {}
end
def initialize(client_id)
#I want to set here, client_id in headers value as a global option.
end
end
现在我想在全局 header 中设置一个值(比如 client_id)。我试过 soap_header
但它将 header 值设置为本地选项。我想在初始化时设置它。它浪费了我很多时间:(所以请帮忙。在此先感谢。
我已经解决了。我们可以轻松地将 headers 设置为全局选项。只需在 initialize
方法中编写以下代码.... :)
client.global.headers { options }