Ruby Net::HTTP::Get and JSON responses

Viewed 49121

I'm trying to connect to an API and retrieve the json results with my rails app, however it doesn't seem to work.

Take for example:

@request = Net::HTTP::Get.new "http://example.com/?search=thing&format=json"

When I try the url in my browser it works! and I get JSON data, however when I try that in Ruby the body is nil.

>> y @request
--- !ruby/object:Net::HTTP::Get 
body: 
body_stream: 
header: 
  accept: 
  - "*/*"
  user-agent: 
  - Ruby
method: GET
path: http://example.com/?search=thing&format=json
request_has_body: false
response_has_body: true

Any thoughts?

2 Answers
Related