Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # https post a payload to a web server with basic authentication
- require 'net/https'
- requests = 1
- protocol = 'https'
- host = 'example.com'
- port = 80
- user = 'example_username'
- pass = 'example_password'
- path = '/some/path'
- content = "<?xml version='1.0'?><test>Hello World! The time is #{Time.now.strftime("%H:%M:%S")}.</test>"
- type = "text/xml"
- uri = URI.parse(protocol + '://' + host + ':' + port.to_s + path)
- io = $stdout
- headers = {
- 'Content-type' => type,
- 'Authorization' => 'Basic ' + [user + ':' + pass].pack('m') }
- requests.times do
- begin
- server = Net::HTTP.new(uri.host, uri.port)
- server.use_ssl = uri.scheme == 'https'
- server.verify_mode = OpenSSL::SSL::VERIFY_NONE
- server.set_debug_output $stderr
- before = Time.now
- response = server.post(uri.request_uri, content, headers)
- after = Time.now
- io.print Time.now.strftime('%H:%M:%S - HTTP ') + response.code + ' ' + response.message + " in #{after-before} seconds\n"
- rescue => ex
- io.print Time.now.strftime('%H:%M:%S - ERR: ') + ex.to_s + '\n'
- end
- io.flush
- end
Add Comment
Please, Sign In to add comment