我无法使用此代码访问tests_controller.rb中的create方法。
String newUrl = "http://10.0.2.2:3000/tests";
httpcon = (HttpURLConnection) ((new URL(newUrl).openConnection()));
httpcon.setDoOutput(true);
httpcon.setRequestProperty("Content-Type", "application/json");
httpcon.setRequestProperty("Accept", "application/json");
httpcon.setRequestMethod("POST");
httpcon.connect();
这是我的routes.rb(我使用模型脚手架来创建RoR应用程序)。
resources :tests
我在路由或其他方面错了。当我在Android中运行此代码时,根本不运行create方法。
答案 0 :(得分:0)
很难说出你失败的原因。你的路线似乎没问题。你可以检查其他事情:
curl
或类似工具从控制台尝试POST请求。当您确定问题的位置时,您可以提出另一个问题,或者更有可能已经在线找到答案。