我似乎當我運行我的應用程序將得到一個錯誤:如何顯示從API的結果,以在軌的意見5
getaddrinfo: Name or service not known
我認爲錯誤的原因有應用程序之間沒有任何聯繫以及使用服務檢索api的服務器。我使用RestClient
gem來訪問請求。
#services/get_games.rb
class GetGames
def self.get_games
response = RestClient::Request.execute(
method: :get,
url: 'https://api-2445582011268.apicast.io.json',
headers: {user_key: ENV["IGDB_API"], accept:'application/json'}
)
end
end
#games_controller
def index
@response = JSON.parse(GetGames.get_games)
@games = Game.all
end
您收到的錯誤是因爲https://api-2445582011268.apicast.io.json是無效的域名。 – Leito
域名是Okey。看來我的錯誤是我錯誤地傳遞了標題。它的工作原理:) –
'io.json'不是一個有效的域,但是,我很高興你使它成功。 – Leito