繁体   English   中英

Android HTTP post请求被解释为ruby服务器上的GET请求

[英]Android HTTP post request being interpreted as a GET request on the ruby server

我将JSON作为POST发送到Heroku服务器上的ruby应用程序(来自Android应用程序)。 正如帖子标题所说,Heroku记录输出:

Started GET "/app_session" for 62.40.34.220 at 2013-05-20 22:12:22 +0000
ActionController::RoutingError (No route matches [GET] "/app_session"):

这是Android请求:

HttpPost httppost = new HttpPost(url.toString());
                    httppost.setHeader("Content-type", "application/json");
                    httppost.setHeader("Accept", "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);

这是路线文件:

resources :app_session, only: [:create, :destroy]

并且rake routes输出:

app_session_index POST   /app_session(.:format)         app_session#create
      app_session DELETE /app_session/:id(.:format)     app_session#destroy

这里发生了什么? 为什么_index添加到app_session 当然这是问题......

这是因为你的资源不是复数。 请参阅Rails 3路由将_index附加到路由名称以获取更多信息。

如果你改变路线,你应该很高兴:

resources :app_sessions, only: [:create, :destroy]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM