Java 类com.badlogic.gdx.Net.HttpResponse 实例源码

项目:libgdxcn    文件:HttpRequestExample.java   
@Override
public void create () {
    HttpRequest request = new HttpRequest(HttpMethods.GET);
    request.setUrl("http://libgdx.badlogicgames.com/nightlies/dist/AUTHORS");
    Gdx.net.sendHttpRequest(request, new HttpResponseListener() {
        @Override
        public void handleHttpResponse (HttpResponse httpResponse) {
            Gdx.app.log("HttpRequestExample", "response: " + httpResponse.getResultAsString());
        }

        @Override
        public void failed (Throwable t) {
            Gdx.app.error("HttpRequestExample", "something went wrong", t);
        }

        @Override
        public void cancelled () {
            Gdx.app.log("HttpRequestExample", "cancelled");
        }
    });
}
项目:gaiasky    文件:DesktopNetworkChecker.java   
private void urlCheck(final String url, final LinkListener listener) {
    HttpRequest request = new HttpRequest(HttpMethods.GET);
    request.setUrl(url);
    request.setTimeOut(TIMEOUT_MS);
    Gdx.net.sendHttpRequest(request, new HttpResponseListener() {
        @Override
        public void handleHttpResponse(HttpResponse httpResponse) {
            if (httpResponse.getStatus().getStatusCode() == HttpStatus.SC_OK) {
                listener.ok(url);
            } else {
                listener.ko(url);
            }
        }

        @Override
        public void failed(Throwable t) {
            listener.ko(url);
        }

        @Override
        public void cancelled() {
            listener.ko(url);
        }
    });

}
项目:Boogie    文件:DownloadUtils.java   
@Override
public void handleHttpResponse(HttpResponse httpResponse)
{
    downloaders.add(this);

    internalToAbsolute(".tmp/").file().mkdir();
    temp.parent().mkdirs();
    try (ReadableByteChannel rbc = Channels.newChannel(httpResponse.getResultAsStream());
            FileOutputStream fos = new FileOutputStream(out))
    {
        fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
        tempFiles.put(filename, temp);
        Gdx.app.log("Download", "Finished downloading " + filename);
    } catch (IOException e)
    {
        e.printStackTrace();
        out.delete();
    }

    downloaders.removeValue(this, false);

    success.run();
}
项目:ead    文件:GATracker.java   
/**
 * Sends the given payload to backend
 */
private void ga(String payload) {
    HttpRequest request = new HttpRequest("POST");
    request.setContent("v=1&tid=" + tracker + "&an=eAdventureDesktop&av="
            + version + "&cid=" + cid + "&" + payload);
    Gdx.net.sendHttpRequest(request, new HttpResponseListener() {
        @Override
        public void handleHttpResponse(HttpResponse httpResponse) {

        }

        @Override
        public void failed(Throwable t) {

        }

        @Override
        public void cancelled() {

        }
    });
}
项目:JavityEngine    文件:WWW.java   
public void GET(String query) {
        if (work)
            return;

        work = true;

        HttpRequestBuilder requestBuilder = new HttpRequestBuilder();
        HttpRequest request = requestBuilder.newRequest().url(urlString).timeout(timeout).content(query).method(HttpMethods.GET).build();

        final WWW my = this;
        Gdx.net.sendHttpRequest(request, new HttpResponseListener() {

            public void handleHttpResponse(HttpResponse httpResponse) {
                responseBytes = httpResponse.getResult();
//              Gdx.app.log("WWW", "Response: " + responseBytes.length);
//              Gdx.app.log("WWW", "Status: " + httpResponse.getStatus().getStatusCode());
                work = false;
                if (wwwResponseListener != null) {
                    Gdx.app.postRunnable(new Runnable() {
                        public void run() {
                            wwwResponseListener.httpResponseListener(my);
                        }
                    });
                }
            }

            public void failed(Throwable t) {
                Gdx.app.error(WWW.class.getSimpleName(), "failed: " + t);
                work = false;
            }

            public void cancelled() {
                Gdx.app.error(WWW.class.getSimpleName(), "cancelled");
                work = false;
            }
        });
    }
项目:gdx-twitter    文件:TwitterAPI.java   
private void sendRequest(final TwitterRequest twitterRequest, final TwitterResponseListener listener) {

        HttpRequestBuilder requestBuilder = new HttpRequestBuilder();
        HttpRequest httpRequest = requestBuilder.newRequest().method(twitterRequest.getRequestType().name()).url(twitterRequest.getUrl()).build();

        // System.out.println(twitterRequest.build().getHeader());
        twitterRequest.build();

        httpRequest.setHeader("Authorization", twitterRequest.getHeader());
        httpRequest.setContent(twitterRequest.getData());
        httpRequest.setTimeOut(config.TWITTER_REQUEST_TIMEOUT);
        Gdx.net.sendHttpRequest(httpRequest, new HttpResponseListener() {

            @Override
            public void handleHttpResponse(HttpResponse httpResponse) {
                if (httpResponse.getStatus().getStatusCode() == 200) {
                    listener.success(httpResponse.getResultAsString());
                } else {
                    listener.apiError(httpResponse.getStatus(), httpResponse.getResultAsString());
                }
            }

            @Override
            public void failed(Throwable t) {
                listener.httpError(t);

            }

            @Override
            public void cancelled() {
                listener.cancelled();
            }
        });

    }
项目:RottenCave    文件:GetListener.java   
@Override
public void handleHttpResponse(HttpResponse httpResponse) {
    String result = httpResponse.getResultAsString();
    rs = json.fromJson(RemoteScore.class, result);

    Gdx.app.debug("Score response", result);
    Gdx.app.debug("Remote score got", 
            "Date : " + rs.getPlayDate() + 
            " / Player name : " + rs.getPlayerName() +
            " / Score : " + rs.getScore());
}
项目:RottenCave    文件:ListListener.java   
@Override
public void handleHttpResponse(HttpResponse httpResponse) {
    HttpStatus status = httpResponse.getStatus();

    if (status.getStatusCode() >= 200 && status.getStatusCode() < 300) {
        String result = httpResponse.getResultAsString();

        Gdx.app.debug("Score response", "ScoresList recieved !");
        Gdx.app.debug("Score response", result);

        @SuppressWarnings("unchecked")
        LinkedList<JsonValue> list = json.fromJson(LinkedList.class, result);

        if (list != null) {
            for (JsonValue jsonValue : list) {
                remoteScores.add(json.readValue(RemoteScore.class, jsonValue));
            }

            Gdx.app.debug("Remote list size", ""+remoteScores.size());
        } else {
            Gdx.app.debug("Score response", "No data to process !");
        }

        Gdx.app.debug("Score response", "Process data");
        processor.processList(remoteScores);
    } else {
        Gdx.app.debug("Score response", "http error, code : "+status.getStatusCode());
        showDialog();
    }
}
项目:gdx-http    文件:DefaultHttpClient.java   
@Override
public void handleHttpResponse(HttpResponse httpResponse) {

    if (cookieMgr != null) {
        List<String> cookieStrings = httpResponse.getHeaders().get("Set-Cookie");
        if (cookieStrings != null) {
            for (String cookie : cookieStrings) {
                cookieMgr.registerSetCookieHeader(cookie, sourceUri);
            }
            cookieMgr.save();
        }
    }
    listener.handleHttpResponse(httpResponse);
}
项目:libgdxcn    文件:DownloadTest.java   
@Override
public void create () {
    batch = new SpriteBatch();
    HttpRequest request = new HttpRequest(HttpMethods.GET);
    request.setUrl("https://www.google.at/images/srpr/logo11w.png");
    Gdx.net.sendHttpRequest(request, new HttpResponseListener() {
        @Override
        public void handleHttpResponse (HttpResponse httpResponse) {
            final byte[] bytes = httpResponse.getResult();

            Gdx.app.postRunnable(new Runnable() {
                @Override
                public void run () {
                    Pixmap pixmap = new Pixmap(bytes, 0, bytes.length);
                    texture = new Texture(new PixmapTextureData(pixmap, pixmap.getFormat(), false, false, true));   
                }
            });     
        }

        @Override
        public void failed (Throwable t) {
            t.printStackTrace();
            Gdx.app.log("EmptyDownloadTest", "Failed", t);
        }

        @Override
        public void cancelled () {
            Gdx.app.log("EmptyDownloadTest", "Cancelled");
        }
    });
}
项目:libgdxcn    文件:NetAPITest.java   
void setText (HttpResponse httpResponse) {
    final String newText = httpResponse.getResultAsString();
    Gdx.app.postRunnable(new Runnable() {
        public void run () {
            text = newText;
        }
    });
}
项目:gaiasky    文件:GaiaCatalogWindow.java   
private String[][] getTAPData(String url, boolean hip, final String format, final GaiaDataListener listener) {
    HttpRequest request = new HttpRequest(HttpMethods.GET);
    request.setUrl(url);
    request.setTimeOut(5000);

    Gdx.net.sendHttpRequest(request, new HttpResponseListener() {
        @Override
        public void handleHttpResponse(HttpResponse httpResponse) {
            if (httpResponse.getStatus().getStatusCode() == HttpStatus.SC_OK) {
                // Ok
                listener.ok(isToArray(httpResponse.getResultAsStream(), format), hip);
            } else {
                // Ko with code
                listener.ko(httpResponse.getStatus().toString());
            }

        }

        @Override
        public void failed(Throwable t) {
            // Failed
            listener.ko();
        }

        @Override
        public void cancelled() {
            // Cancelled
            listener.ko();
        }
    });

    return null;
}
项目:ead    文件:Tracker.java   
/**
 * Loads the client identifier from preferences. If it does not exists,
 * obtains one from bugr.
 */
protected void loadClientId() {
    String clientId = controller.getPreferences().getString(
            Preferences.CLIENT_ID);
    if ("".equals(clientId) || clientId == null) {
        HttpRequest request = new HttpRequest("POST");
        request.setUrl(bugrURL + ACTIVATE_PATH);
        // Obtain an unique id
        Gdx.net.sendHttpRequest(request, new HttpResponseListener() {
            @Override
            public void handleHttpResponse(HttpResponse httpResponse) {
                if (httpResponse.getStatus().getStatusCode() == 200) {
                    cid = httpResponse.getResultAsString();
                    controller.getPreferences().putString(
                            Preferences.CLIENT_ID, cid);
                    // Start session with recently acquired cid
                    startSession();
                } else {
                    Gdx.app.error("Tracker",
                            "Impossible to activate this installation. Server said:\n"
                                    + httpResponse.getResultAsString());
                }
            }

            @Override
            public void failed(Throwable throwable) {
                Gdx.app.error("Tracker",
                        "Impossible to activate this installation.",
                        throwable);
            }

            @Override
            public void cancelled() {

            }
        });
    } else {
        this.cid = clientId;
    }
}
项目:JavityEngine    文件:WWW.java   
public void POST(Object form) {
        if (work)
            return;

        work = true;

        HttpRequestBuilder requestBuilder = new HttpRequestBuilder();
        HttpRequest request = requestBuilder.newRequest().url(urlString).timeout(timeout).jsonContent(form).method(HttpMethods.POST)
                .build();

        final WWW my = this;
        Gdx.net.sendHttpRequest(request, new HttpResponseListener() {

            public void handleHttpResponse(final HttpResponse httpResponse) {
                responseBytes = httpResponse.getResult();

//              Gdx.app.log(WWW.class.getSimpleName(), "response bytes: " + responseBytes.length + " response string: "
//                      + httpResponse.getResultAsString() + " Code: " + httpResponse.getStatus().getStatusCode());

                statusCode = httpResponse.getStatus().getStatusCode();
                work = false;
                if (wwwResponseListener != null) {
                    Gdx.app.postRunnable(new Runnable() {
                        public void run() {
                            wwwResponseListener.httpResponseListener(my);
                        }
                    });
                }
            }

            public void failed(Throwable t) {
                Gdx.app.error(WWW.class.getSimpleName(), "failed: " + t);
                work = false;
            }

            public void cancelled() {
                Gdx.app.error(WWW.class.getSimpleName(), "cancelled");
                work = false;
            }
        });
    }
项目:RottenCave    文件:JsonListener.java   
@Override
public void handleHttpResponse(HttpResponse httpResponse) {
    Gdx.app.debug("Score response", httpResponse.getResultAsString());
}
项目:libgdxcn    文件:NetAPITest.java   
@Override
public void handleHttpResponse (HttpResponse httpResponse) {

    final int statusCode = httpResponse.getStatus().getStatusCode();
    // We are not in main thread right now so we need to post to main thread for ui updates
    Gdx.app.postRunnable(new Runnable() {
        @Override
        public void run () {
            statusLabel.setText("HTTP Request status: " + statusCode);
            setButtonDisabled(false);
        }
    });

    if (statusCode != 200) {
        Gdx.app.log("NetAPITest", "An error ocurred since statusCode is not OK");
        setText(httpResponse);
        return;
    }

    if (clickedButton == btnDownloadImage) {
        final byte[] rawImageBytes = httpResponse.getResult();
        Gdx.app.postRunnable(new Runnable() {
            public void run () {
                Pixmap pixmap = new Pixmap(rawImageBytes, 0, rawImageBytes.length);
                texture = new Texture(pixmap);
            }
        });

    } else if (clickedButton == btnDownloadLarge) {
        Gdx.app.postRunnable(new Runnable() {
            public void run () {
                text = "Retrieving large file...";
            }
        });
        final byte[] rawFileBytes = httpResponse.getResult();
        Gdx.app.postRunnable(new Runnable() {
            public void run () {
                text = "Retrieved large file: " + rawFileBytes.length;
            }
        });

    } else {
        setText(httpResponse);
    }
}
项目:BlockJump    文件:GameScreen.java   
public void getJsonList() {
    HttpRequest httpRequest = new HttpRequest(HttpMethods.GET);
    httpRequest.setUrl("http://24.222.27.154/highscores.json");

    Gdx.net.sendHttpRequest(httpRequest, new HttpResponseListener() {

        @Override
        public void handleHttpResponse(HttpResponse httpResponse) {
            result = httpResponse.getResultAsString();
            Gdx.app.postRunnable(new Runnable() {

                @Override
                public void run() {
                    grabHighScores();
                    createHighScores();
                }

            });
        }

        @Override
        public void failed(Throwable t) {
            Gdx.app.postRunnable(new Runnable() {

                @Override
                public void run() {
                    createHighScores();
                    if (highScoreStage != null) {
                        Dialog dialog = new Dialog("Error", new Skin(
                                Gdx.files.internal("data/uiskin.json")));
                        dialog.text("Connection Error");
                        dialog.button("OK");
                        dialog.show(highScoreStage);
                    }
                }

            });
            result = "";
        }

        @Override
        public void cancelled() {

        }

    });

    // long time = System.currentTimeMillis();
    // while(result == null) {
    // if(System.currentTimeMillis() - time > 5000) {
    // break;
    // }
    // }
    //
    // return result;
}
项目:ead    文件:Updater.java   
@Override
public Object call() throws Exception {
    // Try to download update.json. If updateURL is not present, disable
    // the update system
    if (releaseInfo.getUpdateURL() != null) {
        HttpRequest request = new HttpRequest("GET");
        request.setUrl(releaseInfo.getUpdateURL());
        Gdx.app.debug(LOG_TAG,
                "Trying to retrieve update.json from url:"
                        + releaseInfo.getUpdateURL());
        Gdx.net.sendHttpRequest(request, new HttpResponseListener() {
            @Override
            public void handleHttpResponse(HttpResponse httpResponse) {

                if (httpResponse.getStatus().getStatusCode() == 200) {
                    String data = httpResponse.getResultAsString();
                    Gdx.app.debug(LOG_TAG,
                            "Update.json fetched and read: " + data);
                    try {
                        UpdateInfo updateInfo = controller
                                .getApplicationAssets().fromJson(
                                        UpdateInfo.class, data);

                        if (updateInfo != null) {
                            checkUpdateNeeded(updateInfo);
                        }
                    } catch (SerializationException e) {
                        Gdx.app.error(
                                LOG_TAG,
                                "An error occurred while reading update.json from "
                                        + releaseInfo.getUpdateURL()
                                        + ". The update system will be disabled.",
                                e);
                        setDone();
                    }
                }
            }

            @Override
            public void failed(Throwable t) {
                Gdx.app.debug(
                        LOG_TAG,
                        "Error fetching update.json. Updater will be disabled",
                        t);
                setDone();
            }

            @Override
            public void cancelled() {

            }
        });
    } else {
        Gdx.app.debug(LOG_TAG,
                "The update.json url is null. The update system will be disabled.");
        setDone();
    }

    return null;
}