我尝试在按下按钮后向服务器发送请求,但服务器未收到请求。我在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表
答案 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
是正确的端口。