protected Net.HttpRequest buildRequest(String component, Map<String, String> params) { String request = GJ_GATEWAY + component; request += HttpParametersUtils.convertHttpParameters(params); /* Generate signature */ final String signature; try { signature = md5(request + gjAppPrivateKey); } catch (Exception e) { /* Do not leak 'gamePrivateKey' in log */ Gdx.app.error(GAMESERVICE_ID, "Cannot honor request: " + request, e); return null; } /* Append signature */ String complete = request; complete += "&"; complete += "signature"; complete += "="; complete += signature; final Net.HttpRequest http = new Net.HttpRequest(); http.setMethod(Net.HttpMethods.GET); http.setUrl(complete); return http; }
protected void sendRequest(String method, Map<String, String> params, final NetworkListener listener){ HttpRequest httpPost = new HttpRequest(HttpMethods.POST); httpPost.setUrl(website + method + ".php"); httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded"); httpPost.setContent(HttpParametersUtils.convertHttpParameters(params)); Gdx.net.sendHttpRequest (httpPost, new HttpResponseListener() { public void handleHttpResponse(Net.HttpResponse httpResponse) { String responce = new String(httpResponse.getResult()); String dat = decrypt(responce, ENC_KEY); listener.finished(dat); listener.length(dat.getBytes().length); } public void failed(Throwable t) { listener.failed(t); } public void cancelled(){ } }); }
@Override public Void call() throws Exception { statsReporterVO = crateStatsRequestVO(); try { Net.HttpRequest httpRequest = new Net.HttpRequest(Net.HttpMethods.GET); httpRequest.setUrl(url); httpRequest.setContent(HttpParametersUtils.convertHttpParameters(getParameters())); Gdx.net.sendHttpRequest(httpRequest, new StatsReporterHttpResponseListener()); Gdx.app.debug(TAG, "httpRequest : " + httpRequest.getUrl()); } catch (Exception e) { // no connection no cry e.printStackTrace(); } return null; }
public void makeRequest(final int idEnklave, final ManagerAssets manager){ Preferences pref = Gdx.app.getPreferences("informationLog"); String acces = pref.getString("accesstoken"); HashMap parameters = new HashMap<String,String>(); parameters.put("enklave_id",String.valueOf(idEnklave)); HttpRequestBuilder builder = new HttpRequestBuilder(); Net.HttpRequest request = builder.newRequest().method(Net.HttpMethods.GET).url(url + prof).build(); request.setHeader("Authorization", "Bearer " + acces); request.setContent(HttpParametersUtils.convertHttpParameters(parameters)); Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { if(httpResponse.getStatus().getStatusCode()<300) { String s = httpResponse.getResultAsString(); JSONObject json = new JSONObject(s); enklave.setBricks(json.getInt("nr_bricks")); if (json.getString("faction").contentEquals("null")) { enklave.setFaction(0); } else { enklave.setFaction(json.getInt("faction")); } enklave.setId(json.getInt("id")); enklave.setRooms(json.getInt("rooms")); enklave.setName(json.getString("name")); if(!json.isNull("created_by")) enklave.setUsercreate(json.getJSONObject("created_by").getString("username")); enklave.setLatitude((float) json.getDouble("latitude")); enklave.setLongitude((float) json.getDouble("longitude")); enklave.setExtensions(json.getInt("extensions")); enklave.setTurrets(json.getInt("cells")); if(json.getString("status").contentEquals("InCombat")) { enklave.setStatusCombat(true); enklave.setShields(json.getInt("shield")); enklave.setEnergyBrick(json.getInt("brick_last")); }else{ enklave.setShields(json.getInt("shield_full")); enklave.setEnergyBrick(json.getInt("brick_last")); } enklave.setEnergyBrickfull(json.getInt("brick_full")); enklave.setEnergyfullshield(json.getInt("shield_full")); manager.getAssertEnklaveScreen().setIsupdate(true); Gdx.app.log("information enklave ", "succes " + json); }else{ Gdx.app.log("eroare"+httpResponse.getStatus().getStatusCode(),"meassajul :"+httpResponse.getResultAsString()); new GetEnklaveDetails().makeRequest(ListEnklaves.getInstance().get(idEnklave).id, manager); } } @Override public void failed(Throwable t) { Gdx.app.log("information error failed"," "+ t); new GetEnklaveDetails().makeRequest(ListEnklaves.getInstance().get(idEnklave).id, manager); } @Override public void cancelled() { Gdx.app.log("information error cancelled","cancel"); } }); }