Added HTTP methods to Net

This commit is contained in:
Anuken
2018-02-03 00:57:42 -05:00
parent b83e552b5a
commit 608343b9d1
3 changed files with 29 additions and 0 deletions
+26
View File
@@ -1,5 +1,10 @@
package io.anuke.mindustry.net;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Net.HttpRequest;
import com.badlogic.gdx.Net.HttpResponse;
import com.badlogic.gdx.Net.HttpResponseListener;
import com.badlogic.gdx.net.HttpRequestBuilder;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.IntMap;
import com.badlogic.gdx.utils.ObjectMap;
@@ -242,6 +247,27 @@ public class Net{
active = false;
}
public static void http(String method, String content, Consumer<String> listener){
HttpRequest req = new HttpRequestBuilder().newRequest()
.method(method).content(content).url(serverURL + "/servers").build();
Gdx.net.sendHttpRequest(req, new HttpResponseListener() {
@Override
public void handleHttpResponse(HttpResponse httpResponse) {
listener.accept(httpResponse.getResultAsString());
}
@Override
public void failed(Throwable t) {
Log.err("HTTP error:");
Log.err(t);
}
@Override
public void cancelled() {}
});
}
/**Client implementation.*/
public interface ClientProvider {
/**Connect to a server.*/