protected void loadURL (String url) { displayText("Loading: " + url); try { game.net.req(url).execute().onSuccess(this::displayResult).onFailure(this::displayError); } catch (Exception e) { displayText(e.toString()); } }
if (req.isPost()) { HttpPost httppost = new HttpPost(req.url); if (req.payloadString != null) { hreq.addHeader(HTTP.CONTENT_TYPE, req.contentType()); } else { hreq = new HttpGet(req.url);
conn.setRequestProperty(header.name, header.value); conn.setRequestMethod(req.method()); if (req.isPost()) { conn.setDoOutput(true); conn.setDoInput(true); conn.setAllowUserInteraction(false); conn.setRequestProperty("Content-type", req.contentType()); conn.connect(); conn.getOutputStream().write(
try { XMLHttpRequest xhr = XMLHttpRequest.create(); xhr.open(req.method(), req.url); for (Header header : req.headers) { xhr.setRequestHeader(header.name, header.value); if (req.isPost()) { if (req.payloadBytes != null) throw new UnsupportedOperationException( "Raw bytes not currently supported in HTML5."); xhr.setRequestHeader("Content-Type", req.contentType()); xhr.send(req.payloadString); } else {
Net.Builder b = game.net.req("http://www.posttestserver.com/post.php").setPayload(data); b.addHeader("playn-test", "we love to test!"); b.execute().onFailure(this::displayError).onSuccess(rsp -> { String[] lines = rsp.payloadString().split("[\r\n]+"); String urlPre = "View it at "; else game.net.req(lastPostURL).execute(). onFailure(this::displayError). onSuccess(this::displayResult);
try { XMLHttpRequest xhr = XMLHttpRequest.create(); xhr.open(req.method(), req.url); for (Header header : req.headers) { xhr.setRequestHeader(header.name, header.value); if (req.isPost()) { if (req.payloadBytes != null) throw new UnsupportedOperationException( "Raw bytes not currently supported in HTML5."); xhr.setRequestHeader("Content-Type", req.contentType()); xhr.send(req.payloadString); } else {
conn.setRequestProperty(header.name, header.value); conn.setRequestMethod(req.method()); if (req.isPost()) { conn.setDoOutput(true); conn.setDoInput(true); conn.setAllowUserInteraction(false); conn.setRequestProperty("Content-type", req.contentType()); conn.connect(); conn.getOutputStream().write(
@Override public void init() { Image orange = game.assets.getImage("images/orange.png"); ImageLayer l1 = new ImageLayer(orange); game.rootLayer.addAt(l1.setScale(2).setRotation(FloatMath.PI/8), 50, 50); l1.events().connect(new Mover(l1).listener(game.input)); ImageLayer l2 = new ImageLayer(orange); game.rootLayer.addAt(l2.setScale(1.5f).setRotation(FloatMath.PI/4), 150, 50); l2.events().connect(new Mover(l2).listener(game.input)); Image mdb = game.assets.getRemoteImage("https://www.samskivert.com/images/headshot.jpg"); ImageLayer l3 = new ImageLayer(mdb); game.rootLayer.addAt(l3.setRotation(-FloatMath.PI/4), 50, 150); l3.events().connect(new Mover(l3).listener(game.input)); String l4url = "https://www.samskivert.com/images/2012/12/spellwood-app-icon.png"; game.net.req(l4url).execute().onSuccess(rsp -> { try { Image icon = rsp.payloadImage(new Scale(2)); ImageLayer l4 = new ImageLayer(icon); game.rootLayer.addAt(l4.setRotation(FloatMath.PI/4), 150, 150); l4.events().connect(new Mover(l4).listener(game.input)); } catch (Exception e) { game.log.warn("Failed to decode image: " + e); } }).onFailure(t -> game.log.warn("Failed to load image: " + l4url, t)); }
@Override protected RFuture<Response> execute(Builder req) { RPromise<Response> result = plat.exec().deferredPromise(); NSMutableURLRequest mreq = new NSMutableURLRequest(); mreq.setURL(new NSURL(req.url)); for (Header header : req.headers) { mreq.setHTTPHeaderField(header.name, header.value); } mreq.setHTTPMethod(req.method()); if (req.isPost()) { mreq.setHTTPHeaderField("Content-type", req.contentType()); if (req.payloadString != null) { try { mreq.setHTTPBody(new NSData(req.payloadString.getBytes("UTF-8"))); } catch (UnsupportedEncodingException uee) { throw new RuntimeException(uee); } } else { mreq.setHTTPBody(new NSData(req.payloadBytes)); } } sendRequest(mreq, result); return result; }
@Override public Image getRemoteImage(final String url, int width, int height) { final ImageImpl image = createImage(true, width, height, url); plat.net().req(url).execute(). onSuccess(new Slot<Net.Response>() { public void onEmit (Net.Response rsp) { try { image.succeed(toData(Scale.ONE, new UIImage(new NSData(rsp.payload())))); } catch (Throwable t) { plat.log().warn("Failed to decode remote image [url=" + url + "]", t); image.fail(t); } } }). onFailure(new Slot<Throwable>() { public void onEmit (Throwable cause) { image.fail(cause); } }); return image; }
public String method() { return isPost() ? "POST" : "GET"; }
public String method() { return isPost() ? "POST" : "GET"; }
@Override public String toString() { return "AndroidNet.exec(" + req.method() + ", " + req.url + ")"; }
@Override public void get(String url, Callback<String> callback) { req(url).execute(adapt(callback)); }
@Override public Image getRemoteImage(String url, float width, float height) { final RoboAsyncImage image = new RoboAsyncImage(platform.graphics().ctx, width, height, url); platform.net().req(url).execute(new Callback<Net.Response>() { public void onSuccess (Net.Response rsp) { image.setImage(new UIImage(new NSData(rsp.payload())), Scale.ONE); } public void onFailure (Throwable cause) { image.setError(cause); } }); return image; }
/** * Performs an HTTP GET request to the specified URL. */ public RFuture<String> get(String url) { return req(url).execute().map(GET_PAYLOAD); }
/** Configures the payload of this request as raw bytes with content type * "application/octet-stream". This converts the request to a POST. */ public Builder setPayload(byte[] payload) { return setPayload(payload, "application/octet-stream"); }
protected void loadURL (String url) { displayText("Loading: " + url); try { net().req(url).execute(displayer); } catch (Exception e) { displayText(e.toString()); } }
public void run () { if (lastPostURL == null) displayText("Click 'Post Test' to post some data first."); else net().req(lastPostURL).execute(displayer); } }, x, 10);
@Override public String toString() { return "JavaNet." + req.method().toLowerCase() + "(" + req.url + ")"; } });