Using Net::HTTP.get_print in Rails app
I'm trying to use Net::HTTP.get_开发者_Python百科print
in a rails app to get the response from a URL, and print the URL on the page. My controller contains:
uri_string = "www.example.com"
uri = URI.parse(uri_string)
@contents = Net::HTTP.get_print(uri)
Then the matching .html.erb file contains:
<%= @contents %>
The resulting page is blank, even when I use a dummy URL like "http://www.google.com"
. What am I doing wrong? I'm using Ruby 1.8.7 and Rails 3.0.7 (OS X).
nothing is displayed, because get_print outputs to STDOUT and returns nil. Meaning, you'll be able to see the output in your log, but not on your web page.
use @contents = Net::HTTP.get(uri)
or similar
精彩评论