【问题标题】:LibGDX http request not workingLibGDX http请求不起作用
【发布时间】:2018-06-16 22:41:47
【问题描述】:

当用户在我为 android 设计的 LibGDX 游戏中按下特定按钮时,我想向数据库发送一条字符串消息。我该怎么做呢?以下是我尝试过的代码。但它不起作用。

 Net.HttpRequest httpRequest = new Net.HttpRequest();
    httpRequest.setMethod("POST");
    httpRequest.setUrl("URL is here");
    httpRequest.setContent("INSERT INTO `game_table` (`Button`) VALUES ('Button 1 Pressed')");

    Net.HttpResponseListener httpResponseListener = new Net.HttpResponseListener() {
        @Override
        public void handleHttpResponse(Net.HttpResponse httpResponse) {
            Gdx.app.log("Log httpResponse", httpResponse.getResultAsString());
        }

        @Override
        public void failed(Throwable t) {

        }

        @Override
        public void cancelled() {

        }
    };
    Gdx.net.sendHttpRequest(httpRequest,httpResponseListener);

Log 在 android 监视器中不提供任何内容。我还尝试使用 AsyncTask 而没有 AsyncTask 来实现此代码。但两者都不起作用。 我错过了什么吗?如果是这样,你能给我一个可以工作的小代码 sn-p 吗?

【问题讨论】:

    标签: android libgdx


    【解决方案1】:

    您不需要使用 AsyncTask,libGDX 的 HTTPRequest 是开箱即用的异步。

    如果请求失败或被取消,您没有记录任何内容,所以可能就是这种情况。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-23
      • 2018-04-24
      • 2016-09-21
      相关资源
      最近更新 更多