Mill3r Mill3r - 1 year ago 75
Ruby Question

How to POST a message into a site

I was trying to post a message into a test site with the help of the command

ruby test.rb websiteLink /message POST "***the message***"

I could do it if I write the message in the Ruby code. However I want to find a way to pass a string variable which will enable the user to input the message while giving the above command.

My post code in the test.rb file looks something like this:

def Ruby_test.post_method (host, path)
require 'net/http'

#get the host url: the host parameter is accessed by the command line
uri = URI.parse(host)
#refers to the module the class in is,uri.port)
request ="/messages")
request.set_form_data(:message => "***My Message***")


What is the correct way to pass in a variable which will allow the user to do that?

Answer Source

User input from command line is stored in the ARGV array.


request =[1])    
request.set_form_data(:message => ARGV[3])
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download