use of com.badlogic.gdx.Net.HttpResponse in project libgdx by libgdx.
the class DownloadTest method create.
@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");
}
});
}
use of com.badlogic.gdx.Net.HttpResponse in project libgdx by libgdx.
the class HttpRequestExample method create.
@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");
}
});
}
use of com.badlogic.gdx.Net.HttpResponse in project Mindustry by Anuken.
the class Net method http.
public static void http(String url, String method, Consumer<String> listener, Consumer<Throwable> failure) {
HttpRequest req = new HttpRequestBuilder().newRequest().method(method).url(url).build();
Gdx.net.sendHttpRequest(req, new HttpResponseListener() {
@Override
public void handleHttpResponse(HttpResponse httpResponse) {
listener.accept(httpResponse.getResultAsString());
}
@Override
public void failed(Throwable t) {
failure.accept(t);
}
@Override
public void cancelled() {
}
});
}
Aggregations