Skip to content

Instantly share code, notes, and snippets.

@gkolok
Created November 25, 2010 13:28
Show Gist options
  • Save gkolok/715391 to your computer and use it in GitHub Desktop.
Save gkolok/715391 to your computer and use it in GitHub Desktop.
simple ruby soap post with basic authentication
require 'net/http'
request_body = <<EOF
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.host/">
<soapenv:Header/>
<soapenv:Body>
<ser:createGroup>
<arg0>
<description>#{description}</description>
<name>#{name}</name>
</arg0>
</ser:createGroup>
</soapenv:Body>
</soapenv:Envelope>
EOF
uri = URI.parse('http://service.host/service')
post = Net::HTTP::Post.new(uri.path, 'content-type' => 'text/xml;charset=UTF-8')
post.basic_auth 'username', 'pass'
Net::HTTP.new(uri.host, uri.port).start {|http|
http.request(post, request_body) {|response|
put response.
put response.read_body
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment