Send a SOAP request to a url that requires basic authenticat

Discussion in 'Ruby' started by Chris Gunnels, Feb 4, 2010.

  1. 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?
     
    Chris Gunnels, Feb 4, 2010
    #1
    1. Advertisements

  2. 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
     
    Jeremy Hinegardner, Feb 4, 2010
    #2
    1. Advertisements

  3. Chris Gunnels, Feb 4, 2010
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.