Send a SOAP request to a url that requires basic authenticat

C

Chris Gunnels

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?
 
J

Jeremy Hinegardner

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?

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top