public final String[] post(String url, String json) { String[] result = new String[2]; try { HttpPost httpPost = new HttpPost(new URI(url)); httpPost.setHeader("Content-type", "application/json"); StringEntity sEntity = new StringEntity(json, "UTF-8"); httpPost.setEntity(sEntity); HttpResponse response; response = HttpClientSingleton.getHttpClientInstace().execute(httpPost); HttpEntity entity = response.getEntity(); if (entity != null) { result[0] = String.valueOf(response.getStatusLine().getStatusCode()); InputStream instream = entity.getContent(); result[1] = toString(instream); instream.close(); Log.d("post", "Result from post JsonPost : " + result[0] + " : " + result[1]); } } catch (Exception e) { Log.e("NGVL", "Falha ao acessar Web service", e); result[0] = "0"; result[1] = "Falha de rede!"; } return result; }
public final String[] get(String url) { String[] result = new String[2]; HttpGet httpget = new HttpGet(url); HttpResponse response; try { response = HttpClientSingleton.getHttpClientInstace().execute(httpget); HttpEntity entity = response.getEntity(); if (entity != null) { result[0] = String.valueOf(response.getStatusLine().getStatusCode()); InputStream instream = entity.getContent(); result[1] = toString(instream); instream.close(); Log.i("get", "Result from post JsonPost : " + result[0] + " : " + result[1]); } } catch (Exception e) { Log.e("NGVL", "Falha ao acessar Web service", e); result[0] = "0"; result[1] = "Falha de rede!"; } return result; }