views:

28

answers:

2

Im working on a small project which I need to send a couple of parameters to another server which has a web service for sending of SMS messages. I'm constructing the URL by calling a method on my controller like so,

...
send_sms(number,message)
   sms_url = "http://sms-machine.xx.xx/sendsms/" + number + "/" + message
   #go to the url above
end

The resulting page will be a delivery message from the server with either a "NO" or "YES" to show if the message was sent. It is important for the users to know if the sms message was sent or not. So my question is how do I visit the sms url. Is there such a go_to_url function in rails?

+2  A: 

You can use Ruby's Net::HTTP or the much simpler open-uri functionality, eg:

require 'open-uri'

status = open("http://sms-machine.xx.xx/sendsms/#{number}/#{message}").read

Net:HTTP is loaded by default.

jdeseno
thank you jdeseno, works like a charm
kibyegn
A: 

You can use the standard net/http library to make your own HTTP requests: http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/index.html

sarnold