Ruby:Sinatra:Thin上无法访问Web服务

时间:2014-05-08 11:28:55

标签: ruby web-services sinatra

我在Thin Web服务器上的centOS中运行了一个ruby sinatra Web服务。 我无法通过 210.71.253.59:3001/swap 远程连接到它。 (它确实适用于localhost),一切似乎都很好:

-bash-4.1$ ruby spotify_token_swap.rb 
== Sinatra/1.4.5 has taken the stage on 3001 for development with backup from Thin
Thin web server (v1.6.2 codename Doc Brown)
Maximum connections set to 1024
Listening on 210.71.253.59:3001, CTRL+C to stop

我已经确认3001端口已打开。 (我看过类似的帖子Ruby Sinatra Webservice running on localhost:4567 but not on IP,仍然无法解决)

任何想法为什么,或者我做错了什么? 这是我的.rb:

require 'rubygems'
require 'sinatra'
require 'net/http'
require 'net/https'

set :bind, '210.71.253.59'
set :port, 3001

post '/swap' do

    auth_code = params[:code]

    uri = URI.parse("https://ws.spotify.com")
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE

    request = Net::HTTP::Post.new("/oauth/token")
    request.form_data = {
        "grant_type" => "authorization_code",
        "client_id" => kClientId,
        "client_secret" => kClientSecret,
        "redirect_uri" => kClientCallbackURL,
        "code" => auth_code
    }

    response = http.request(request)

    status response.code.to_i
    return response.body

end

1 个答案:

答案 0 :(得分:0)

以防有人遇到同样的问题:

很简单...... 不要忘记检查 iptables ,在我的情况下,它阻止了传入连接。