【发布时间】:2015-07-06 19:57:20
【问题描述】:
我已经构建了一个与 Android 应用程序交互的 Rails 应用程序。在 localhost 上从 android 发送和接收数据工作正常。但是当我上传到 AWS EC2 实例时,我只能将数据从 android 发送到服务器,而不是相反。
我正在使用乘客 gem 在 AWS 中上传。
我的 rails 代码接受来自应用程序的请求,它给出 200 OK
class Android::OnetimeloginController < ApplicationController
respond_to :json
# This handles one time login from the android app
def create
# Takes up the credentials from the android app and
# sends the header token to be used for further pings
credentials = permitted_credentials
# Checks the credentials and renders the responses
if credentials.has_key?("name")
if Branch.exists?(name: credentials["something"]) && credentials["password"] == "something"
response_json = {"response" => "Yes"}
render :json => response_json
else
render :text => "NO"
end
end
end
private
def permitted_credentials
params.require("credentials").permit(:name, :password, :tablet_id)
end
end
但我在 android 端没有得到任何东西(尽管我在 localhost 中得到响应)
我什至收到了我的 CURL 请求的响应。 我的 curl 命令。
curl -v -H "Content-type: application/json" -X POST -d ' {"credentials":{"name" : "something", "password": "something"}}' http://IP/path_to_controller
我检查了从 android 请求中放置“Content-type”和“Accept”标头,但没有用。
请告诉我哪里出错了?是 AWS 的问题吗?
【问题讨论】:
-
您是从移动网络浏览器中的页面发出请求吗?如果是这样,该网页从哪里获得服务?
-
@Emil 我正在使用 volley 从 android 应用发出请求,但没有任何响应
-
您在服务器日志中看到您的请求和响应吗?
-
是的,Emil 我收到了来自 android 的请求,并且来自 rails 服务器的响应是 200 OK。
-
因此您可以在本地主机上使用 curl 从 EC2 获取响应,但相同的请求不会在移动设备上为您提供任何响应。这很棘手。我不知道,但我建议您使用调试器来查看在您使用移动设备中的 HTTP 客户端发出请求后发生了什么。
标签: android ruby-on-rails amazon-web-services amazon-ec2 passenger