Sinatra Net::HTTP causes timeouts on a simple request

此生再无相见时 提交于 2020-01-05 04:22:18

问题


I have a small simple Net::HTTP POST request to do to my Sinatra app:

def collect(website)
    uri = URI("http://localhost:9393/save/#{website}")
    res = Net::HTTP.post_form(uri, 'q' => 'ruby', 'max' => '50')
    puts res.body
end

But it causes a timeout. Here is the request handler:

post '/save/:website' do |website|
    puts request.body
    "done"
end

I never reach the puts nor the done. My shotgun server is running on port 9393 of course. When I use the REST Console extension and paste valid json in it, it works for that same path.

What is causing this Timeout::Error?


回答1:


So the weird thing is, I changed my server from shotgun to simply running it with sinatra and the gem sinatra/reloader. I was using shotgun because it would auto reload whenever the source file changed, and sinatra itself didn't.

After ditching shotgun, it worked straight away.



来源:https://stackoverflow.com/questions/15641970/sinatra-nethttp-causes-timeouts-on-a-simple-request

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!