0

好吧,标题几乎说明了我想做的事情。如何通过单击 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;
}
4

2 回答 2

0

您正在使用外部/互联网 IP 地址。为此,您确实必须配置路由器。路由器应将使用的端口转发到运行服务器的电脑。使用PC的LAN地址要容易得多,因为您不必转发。用 ipconfig 找出 pc 的 LAN ip。

于 2014-06-25T14:21:23.503 回答
0

有多种方法可以将您的应用程序连接到 localhost。一种简单的方法是通过您的手机(热点或网络共享)将您的计算机与互联网连接。打开终端并运行 ifconfig 并获取 USB 连接(网络共享)提供的 IP 地址。使用此 IP 而不是 (localhost)。

于 2014-06-25T14:21:52.980 回答