如何将请求发送到服务器

时间:2019-11-30 10:41:00

标签: android server

我尝试在按下按钮后向服务器发送请求,但服务器未收到请求。我在gradle文件中连接到项目gridmi api库并对其进行了同步。如何发送请求?

@Override
public void onClick(View v) {

    GridmiAPI.init("http://localhost/demo/", 10000, JSONObject.class);

    GridmiAPI.Request request = new GridmiAPI.Request("message");

    GridmiAPI.onRequest(this, request, new GridmiAPI.Handler.OUT() {

        @Override
        protected void onSuccess(GridmiAPI.Response response) {
            Log.d("logsuc", "ok");
        }

        @Override
        protected void onFailed(Exception exception) {
        }

    });

}

通过php收到请求后,我需要更新mysql表

1 个答案:

答案 0 :(得分:0)

onRequest之后调用start方法:

@Override
public void onClick(View v) {

    GridmiAPI.init("http://localhost/demo/", 10000, JSONObject.class);

    GridmiAPI.Request request = new GridmiAPI.Request("message");

    GridmiAPI.onRequest(this, request, new GridmiAPI.Handler.OUT() {

        @Override
        protected void onSuccess(GridmiAPI.Response response) {
            Log.d("logsuc", "ok");
        }

        @Override
        protected void onFailed(Exception exception) {
        }

    }).start();

}

还要确保http://localhost/demo/是真实的服务器路径,而10000是正确的端口。

相关问题