1
votes

I want to post an XML from my server to other server so I am using the following code

#!/usr/bin/ruby
require 'net/http'
require 'cgi'
require "rubygems"

uuid = "_10.223.18.88.8734589732985756"
t= Time.now

soapEnvelop = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Header/><SOAP-ENV:Body><samlp:Request xmlns:samlp=\"urn:oasis:names:tc:SAML:1.0:protocol\"  MajorVersion=\"1\" MinorVersion=\"1\" RequestID=\"#{uuid}\" IssueInstant=\"#{t}\"><samlp:AssertionArtifact>ST-askdb4YfcMasnH9nrItd-vm-cas2</samlp:AssertionArtifact></samlp:Request></SOAP-ENV:Body></SOAP-ENV:Envelope>"

url = URI.parse('https://10.223.18.78/sso/samlValidate?TARGET=http://10.223.18.88/')
request = Net::HTTP::Post.new(url.path)

request.body="<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Header/><SOAP-ENV:Body><samlp:Request xmlns:samlp=\"urn:oasis:names:tc:SAML:1.0:protocol\"  MajorVersion=\"1\" MinorVersion=\"1\" RequestID=\"#{uuid}\" IssueInstant=\"#{t}\"><samlp:AssertionArtifact>ST-askdb4YfcMasnH9nrItd-vm-cas2</samlp:AssertionArtifact></samlp:Request></SOAP-ENV:Body></SOAP-ENV:Envelope>"
response = Net::HTTP.start(url.host, url.port) {|http| http.request(request)}

puts response

while I execute I am getting the following error:

/root/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/net/protocol.rb:135:in `sysread': end of file reached (EOFError)

from /root/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/net/protocol.rb:135:in `rbuf_fill'

    from /root/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/timeout.rb:62:in `timeout'

    from /root/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/timeout.rb:93:in `timeout'

    from /root/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/net/protocol.rb:134:in `rbuf_fill'

    from /root/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/net/protocol.rb:116:in `readuntil'

    from /root/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/net/protocol.rb:126:in `readline'

    from /root/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/net/http.rb:2026:in `read_status_line'

    from /root/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/net/http.rb:2015:in `read_new'

    from /root/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/net/http.rb:1051:in `request'

    from samlRequest.rb:17

    from /root/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/net/http.rb:543:in `start'

    from /root/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/net/http.rb:440:in `start'

    from samlRequest.rb:17

Not sure what the problem is. Please help.. Thanks in advance.

2

2 Answers

2
votes

Since this is obviously a SOAP exchange, I'd recommend using Savon or SOAP4R, rather than rolling your own SOAP client. This will give you a lot more capability, and be no more complex (and possibly much less, depending on what you're trying to do). Take a look at the Savon documentation for more information.

0
votes

since it's https, you should also :

require 'net/https'

and

request = Net::HTTP::Post.new(url.path)
request.use_ssl = true

not sure if it's going to solve your problem though. Just let us know the results