问题描述
我对我的Sinatra应用有一个简单的Net::HTTP
POST请求:
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
我从不到达puts
或done
.我的shotgun
服务器当然在端口9393上运行.当我使用REST控制台扩展并将有效的json粘贴到其中时,它适用于同一路径.
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.
是什么原因导致此Timeout :: Error?
What is causing this Timeout::Error?
推荐答案
所以很奇怪,我将服务器从shotgun
更改为仅使用sinatra
和gem sinatra/reloader
运行它.我使用的是shotgun
,因为只要源文件发生更改,它就会自动重新加载,而sinatra
本身没有更改.
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.
抛弃shotgun
后,它立即起作用.
After ditching shotgun
, it worked straight away.
这篇关于Sinatra Net :: HTTP在一个简单的请求上导致超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!