我正在尝试从移动应用程序登录我的网络应用程序,但出现服务器错误 (500),并且 ruby 端的参数为空。我觉得这很奇怪,因为我可以使用相同的过程很好地注册,即以 JSON 格式发送数据并在控制器中运行创建操作。
在 ruby 应用程序接收 JSON 并填充参数的位置之间我是否缺少一个步骤?
这是控制器:
def create
user = User.find_by_email(params[:app_session][:email].downcase)
if user && user.authenticate(params[:app_session][:password])
respond_with do|format|
format.json { render json: user }
end
else
respond_with do|format|
format.json { render json: { :info => "Failed" }}
end
end
end
这是java代码:(我知道密码是公开的,这将得到解决)
@Override
protected Object doInBackground(Void... params) {
try {
URL url = new URL(myurl);
//json.put("success", true);
json.put("email", mUserEmail);
json.put("password", mUserPassword);
HttpClient httpclient = new DefaultHttpClient();
HttpParams myParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(myParams, 10000);
HttpConnectionParams.setSoTimeout(myParams, 10000);
try {
HttpPost httppost = new HttpPost(url.toString());
httppost.setHeader("Accept", "application/json");
httppost.setHeader("Content-type", "application/json");
StringEntity se = new StringEntity(json.toString());
httppost.setEntity(se);
HttpResponse response = httpclient.execute(httppost);
String temp = EntityUtils.toString(response.getEntity());
jsonResponse = new JSONObject(temp);
value = true;
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
} catch (JSONException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} finally {
}
return value;
}
编辑:这里是 Heroku 日志:
Started GET "/app_session" for 62.40.34.218 at 2013-05-20 19:14:01 +0000
Processing by AppSessionController#create as JSON
Parameters: {"app_session"=>{}}
Completed 200 OK in 2ms (Views: 0.2ms | ActiveRecord: 1.0ms)