在 Sinatra 中获取客户端的 IP 地址?
这是一个非常简单的问题,但我在任何地方都找不到任何提及这一点的信息。
我如何从 Sinatra 中获取客户端的 IP 地址?
get '/' do
"Your IP address is #{....}"
end
This is a really simple question, but I cannot find any mention of this, anywhere..
How do I get the client's IP address from in Sinatra?
get '/' do
"Your IP address is #{....}"
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Sinatra 提供了一个
request
对象,这是您应该使用的客户端请求数据的接口。使用
request.ip
是查找客户端 IP 地址的首选方法:Sinatra provides a
request
object, which is the interface to the client request data that you should be using.Using
request.ip
is the preferred method to find the client's IP address:无论如何,我要发布答案..所以:
Sinatra 使用 Rack ::Request API,因此您可以使用其中的许多可用内容。
还有一个指向 Sinatra 文档 的链接。
I was coming to post the answer anyway.. so:
Sinatra uses the Rack::Request API, so you can use a lot of things available in it.
Also a link to the Sinatra doc's.