0

I have a device which is connected via ethernet and receives settings via a web browser interface.
When the user clicks "Update Settings" the button calls a URL which has the format

{{IP}}/cgi-bin/webinterfaceSharedMemoryClient.cgi?key=value&key=value&key=value

where the {{IP}} is the set IP of the device.

Does anyone have an idea how I could send this using Ruby, without using a web browser?

1
  • Depending on the method used, whether it's POST or GET, you can use a number of different libraries or gems: OpenURI is the easiest, things like HTTPClient or Curb are nicely featured but a bit more complex, down to Net::HTTP which is very powerful but spirals into complexity quickly. OpenURI doesn't support POST, but the rest do. Commented Nov 16, 2013 at 4:21

3 Answers 3

2

Easiest:

require 'open-uri'
url = "IP/cgi-bin/webinterfaceSharedMemoryClient.cgi?key=value&key=value&key=value"
response = open(url) { |io| io.read }

With more control, use Net::HTTP.

Sign up to request clarification or add additional context in comments.

Comments

1

There's a library called Net in ruby which should do what you want. The simplest usage would be something like:

require 'net/http'

uri = URI('http://#.#.#.#/cgi-bin/webinterfaceSharedMemoryClient.cgi?key=value&key=value&key=value')
Net::HTTP.get(uri) # => results

this is essentially from the Ruby 2.0 documentation here: http://ruby-doc.org/stdlib-2.0.0/libdoc/net/http/rdoc/Net/HTTP.html

Comments

1

Another option is the mechanize gem. Here's an example:

require 'mechanize'

agent = Mechanize.new
page = agent.get "http://www.example.org/"
page.link_with(:text => 'More information...').click

1 Comment

"wrong header line format" Each of the above appear to work in a round about way though it would appear I am missing something. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.