Send a SOAP request to a url that requires basic authenticat

Hey all,

I have scoured the web looking for an answer but can’t seem to find one.
I need to send a SOAP request to a server that requires basic
authentication. I can create the base64 encoded username and password
that the server requires, but I can’t seem to send that or add that to
the header as the server requires.

code i have right now:
ENDPOINT = “https://asldfjlsf.com
request_xml_string = ‘xml…’
stream = SOAP::HTTPStreamHandler.new(SOAP::Property.new)

header = SOAP::SOAPHeader.new
header.add(“authorization”,
HTTPAuth::Basic.pack_authorization(“username”, “pass”))
body_item = SOAP::SOAPElement.new(‘getResponse’, request_xml_string)
body = SOAP::SOAPBody.new(body_item)
envelope = SOAP::SOAPEnvelope.new(header, body)
request_string = SOAP::Processor.marshal(envelope)
request = SOAP::StreamHandler::ConnectionData.new(request_string)

resp_data = stream.send(ENDPOINT, request, ‘getResponse’)

puts “Got response:”
puts resp_data.receive_string

Any help?

On Fri, Feb 05, 2010 at 05:30:16AM +0900, Chris G. wrote:

request_xml_string = ‘xml…’

resp_data = stream.send(ENDPOINT, request, ‘getResponse’)

puts “Got response:”
puts resp_data.receive_string

Any help?

I believe you are mixing 2 differen authentication mechanisms.

  1. HTTP Basic Authentication - Done when the server sends an HTTP Header
    similar to:

     WWW-Authenticate: Basic realm="my secure location"
    

    The response will be in an HTTP Header, something like:

     Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
    
  2. SOAP Authentication - done via the XML SOAP format, this will
    probably be donw with a SOAP header inside the SOAP envelope.

It looks to me in your code as if you are sending a SOAP header for
the SOAP request, and you probably want to send an HTTP header instead.

enjoy,

-jeremy

I just installed Savon gem and did the following to get it to work:

@client = Savon::Client.new “https://asdflskdjf.com
@client.request.basic_auth(“user”, “pass”)
@client.soap_action_you_want_to_execute

Find docs at http://rdoc.info/projects/rubiii/savon