1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| private static void initHttpClient(){
if(httpclient == null){
httpclient = new DefaultHttpClient();
Log.i("","initialisation de httpClient");
}
}
public static Object recupérer() {
Object res = null;
initHttpClient();
HttpGet httpget = new HttpGet("mon url");
try {
response = httpclient.execute(httpget);
entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
String str = convertStreamToString(instream);
//Mes opérations
instream.close();
}
} catch (ClientProtocolException e) {
Log.e("REST", "There was a protocol based error", e);
} catch (IOException e) {
Log.e("REST", "There was an IO Stream related error", e);
}
return res;
} |
Partager