好吧,标题几乎说明了我想做的事情。如何通过单击 Android 应用程序中的按钮将 JSON 对象发布到我的 localhost:9000(以播放框架开始)。
我已经使用 AsyncTask 完成了 android 方法来发布我的 JSON 对象,它适用于其他 API。但是,我不确定如何将其发布到我的 localhost:9000 中,因为我想将后者用作 REST API。我是否必须在播放的路由或配置文件中写一些东西才能接收 JSON 对象?例如,
GET /someplace Controllers.applications.index()
如果这有帮助,这是我在 android asynctask 中执行帖子的方法:
@Override
protected String doInBackground(String... params) {
JSONObject test = new JSONObject();
try {
test.put("Products", params[0]);
} catch (JSONException e) {
e.printStackTrace();
}
String send = test.toString();
send = "Products=" + send;
// localhost is my actual IP address
executePost("http://<localhost>:9000/request",send);
return null;
}