Search in sources :

Example 1 with HttpResponse

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");
        }
    });
}
Also used : HttpRequest(com.badlogic.gdx.Net.HttpRequest) HttpResponse(com.badlogic.gdx.Net.HttpResponse) PixmapTextureData(com.badlogic.gdx.graphics.glutils.PixmapTextureData) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) Pixmap(com.badlogic.gdx.graphics.Pixmap) HttpResponseListener(com.badlogic.gdx.Net.HttpResponseListener)

Example 2 with HttpResponse

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");
        }
    });
}
Also used : HttpRequest(com.badlogic.gdx.Net.HttpRequest) HttpResponse(com.badlogic.gdx.Net.HttpResponse) HttpResponseListener(com.badlogic.gdx.Net.HttpResponseListener)

Example 3 with HttpResponse

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() {
        }
    });
}
Also used : HttpRequest(com.badlogic.gdx.Net.HttpRequest) HttpResponse(com.badlogic.gdx.Net.HttpResponse) HttpRequestBuilder(com.badlogic.gdx.net.HttpRequestBuilder) HttpResponseListener(com.badlogic.gdx.Net.HttpResponseListener)

Aggregations

HttpRequest (com.badlogic.gdx.Net.HttpRequest)3 HttpResponse (com.badlogic.gdx.Net.HttpResponse)3 HttpResponseListener (com.badlogic.gdx.Net.HttpResponseListener)3 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 Texture (com.badlogic.gdx.graphics.Texture)1 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)1 PixmapTextureData (com.badlogic.gdx.graphics.glutils.PixmapTextureData)1 HttpRequestBuilder (com.badlogic.gdx.net.HttpRequestBuilder)1