【问题标题】:Unable to send data from rails app in aws to android app无法将数据从aws中的rails应用程序发送到android应用程序
【发布时间】: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


【解决方案1】:

我有同样的错误。它不是您的 rails 脚本的问题。我认为您使用的 volley 框架可能已损坏或有问题。尝试使用 gradle 从任何其他来源导入库。尝试从 mcxiaoke.volley 导入。它对我有用....

【讨论】:

  • 感谢 Nikhil Gopinath...我没想到问题会出在截击上。像魅力一样工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-11
  • 1970-01-01
  • 2015-04-11
  • 1970-01-01
  • 2014-02-19
相关资源
最近更新 更多