问题
I'm trying to send soap request with basic authentication with savon gem
My soap server is set up with wash_out gem
class OrdersController < ApplicationController
soap_service namespace: 'sir:WashOut', wsse_username: SIRA[:auth][:username], wsse_password: SIRA[:auth][:password]
....
When i make a request to soap server via savon
i get an error:
@client = Savon.client(
wsdl: "http://localhost:3000/orders/wsdl",
soap_header: { 'Username' =>SIRA[:auth][:username], 'Password' => SIRA[:auth][:password] }
)
@response = @client.call(:notify ).to_hash
On the last command i get an error
Savon::SOAPFault: (Server) Missing required UsernameToken
回答1:
client = Savon.client(
wsdl: 'http://service.example.com?wsdl',
soap_header: {
"AuthenticateRequest" =>
{"apiKey" => "****** your api *********"}},
pretty_print_xml: true)
client.operations
response = client.call(:function)
Note: "apiKey" is my prams to authenticate, your can be different
回答2:
I've tried this and it works!
@client = Savon.client(
wsdl: "http://localhost:3000/orders/wsdl",
wsse_auth: [SIRENA[:auth][:username], SIRENA[:auth][:password] ],
logger: Rails.logger
)
@response = @client.call(:notify, ).to_hash
回答3:
For Savon 2. Basic authorization can be done as follows:
@client = Savon.client(
wsdl: "http://localhost:3000/orders/wsdl",
basic_auth: ["username", "password"]
)
@response = @client.call(:notify ).to_hash
来源:https://stackoverflow.com/questions/28434493/rails-pass-soap-basic-auth-with-savon