I am working on some RoR3 app and I have to make a HTTP request to some server.
I tried Ruby's Net::HTTP lib and is working locally but not on Heroku. I then tried HTTParty and get it to work locally but it still doesn't work on Heroku. I get
We're sorry, but something went wrong.
When I check the Heroku logs I get
500 Internal server error
showing as the last log.
I made sure the 'httparty' gem is mentioned in the right place in gemfile.
Is there any tutorial on how to make a HTTP request from Heroku PaaS?
Thanks
Amit Suroliya was correct. I was using HTTParty as well and it was working through Curl and Development but would crash in production. Because the HTTParty parameter is the literal URL(as a string), it has to be a flawless URL/URI (meaning no spaces). My bad URI was as follows:
HTTParty.get("http://api.blahblahblah.com/v1/Boards/Search?&limit=79&query=#{query}&filter_date_from=1423353600")
Notice the interpolation query=#{query}"
, So if query='Michelle Obama'
, notice space between Michelle
and Obama
. Because of interpolation, the HTTParty.get('string')
it is incorrect.
SOLUTION:
Replace all whitespaces within your string with +
, or you could use %20
.
I used query.gsub!(' ', '+')
For more info on whitespace in the URL check it out here: Spaces in URLs?