无法将数据从 aws 中的 rails 应用程序发送到 android 应用程序
Unable to send data from rails app in aws to android app
我构建了一个与 android 应用程序交互的 rails 应用程序。在本地主机上从 android 发送和接收数据工作正常。但是当我上传到 AWS EC2 实例时,我只能将数据从 android 发送到服务器,而不是相反。
我正在使用 passenger 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 方面没有得到任何东西(尽管我在本地主机上得到响应)
我的 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" headers,但没有用。
请告诉我哪里错了?是 AWS 的问题吗?
我有同样的错误。这不是您的 rails 脚本的问题。我认为您使用的 volley 框架可能已损坏或有问题。尝试使用 gradle 从任何其他来源导入库。尝试从 mcxiaoke.volley 导入。它对我有用....
我构建了一个与 android 应用程序交互的 rails 应用程序。在本地主机上从 android 发送和接收数据工作正常。但是当我上传到 AWS EC2 实例时,我只能将数据从 android 发送到服务器,而不是相反。
我正在使用 passenger 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 方面没有得到任何东西(尽管我在本地主机上得到响应)
我的 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" headers,但没有用。
请告诉我哪里错了?是 AWS 的问题吗?
我有同样的错误。这不是您的 rails 脚本的问题。我认为您使用的 volley 框架可能已损坏或有问题。尝试使用 gradle 从任何其他来源导入库。尝试从 mcxiaoke.volley 导入。它对我有用....