Guest User

Untitled

a guest
Mar 14th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. # https post a payload to a web server with basic authentication
  2. require 'net/https'
  3.  
  4. requests = 1
  5. protocol = 'https'
  6. host = 'example.com'
  7. port = 80
  8. user = 'example_username'
  9. pass = 'example_password'
  10. path = '/some/path'
  11. content = "<?xml version='1.0'?><test>Hello World! The time is #{Time.now.strftime("%H:%M:%S")}.</test>"
  12. type = "text/xml"
  13.  
  14. uri = URI.parse(protocol + '://' + host + ':' + port.to_s + path)
  15. io = $stdout
  16.  
  17. headers = {
  18. 'Content-type' => type,
  19. 'Authorization' => 'Basic ' + [user + ':' + pass].pack('m') }
  20.  
  21. requests.times do
  22. begin
  23. server = Net::HTTP.new(uri.host, uri.port)
  24. server.use_ssl = uri.scheme == 'https'
  25. server.verify_mode = OpenSSL::SSL::VERIFY_NONE
  26. server.set_debug_output $stderr
  27.  
  28. before = Time.now
  29.  
  30. response = server.post(uri.request_uri, content, headers)
  31.  
  32. after = Time.now
  33.  
  34. io.print Time.now.strftime('%H:%M:%S - HTTP ') + response.code + ' ' + response.message + " in #{after-before} seconds\n"
  35. rescue => ex
  36. io.print Time.now.strftime('%H:%M:%S - ERR: ') + ex.to_s + '\n'
  37. end
  38. io.flush
  39. end
Add Comment
Please, Sign In to add comment