List of usage examples for org.apache.http.impl.client DefaultHttpClient DefaultHttpClient
public DefaultHttpClient()
From source file:com.cdhxqh.travel_ticket_app.weather.HttpRetriever.java
public static String retrieve(String url) { HttpGet request = new HttpGet(url); try {//from w w w . j av a2 s . c o m HttpResponse response = new DefaultHttpClient().execute(request); HttpEntity entity = response.getEntity(); if (entity != null) { return EntityUtils.toString(entity); } } catch (IOException e) { Log.e(TAG, "Couldn't retrieve data from url " + url, e); } return null; }
From source file:brooklyn.event.feed.http.HttpPolls.java
public static HttpToolResponse executeSimpleGet(URI uri) { return HttpTool.httpGet(new DefaultHttpClient(), uri, ImmutableMap.<String, String>of()); }
From source file:middleware.HTTPRequest.java
public static List<Vuelo> doGetVuelos() throws IOException { String result;/*from www .j av a 2 s . c om*/ String url = "http://localhost:8084/MVIv2/webapi/vuelos"; DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet getRequest = new HttpGet(url); getRequest.addHeader("Accept", "application/json"); HttpResponse response = httpClient.execute(getRequest); if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException("ERROR AL CONSULTAR DEL TIPO: " + response.getStatusLine().getStatusCode()); } HttpEntity entity = response.getEntity(); result = EntityUtils.toString(entity); List<Vuelo> listaVuelos = getArrayVuelo(result); httpClient.getConnectionManager().shutdown(); return listaVuelos; }
From source file:com.ammobyte.radioreddit.api.InternetCommunication.java
public static InputStream retrieveStream(String url) { DefaultHttpClient client = new DefaultHttpClient(); HttpGet getRequest = new HttpGet(url); try {//from w w w.j a va2s. co m HttpResponse getResponse = client.execute(getRequest); final int statusCode = getResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { Log.w("InternetConnection", "Error " + statusCode + " for URL " + url); return null; } HttpEntity getResponseEntity = getResponse.getEntity(); return getResponseEntity.getContent(); } catch (IOException e) { getRequest.abort(); Log.w("InternetConnection", "Error for URL " + url, e); } return null; }
From source file:org.eclipse.epp.internal.mpc.core.util.HttpUtil.java
public static HttpClient createHttpClient(String baseUri) { HttpClient client = new DefaultHttpClient(); client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, MarketplaceClientCore.BUNDLE_ID); if (baseUri != null) { configureProxy(client, baseUri); }//w w w . j a v a 2 s . c o m return client; }
From source file:no.kantega.kwashc.server.test.HttpClientUtil.java
static HttpClient getHttpClient() { HttpClient httpClient = new DefaultHttpClient(); // timeout: 5 seconds httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 5 * 1000); httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5 * 1000); return httpClient; }
From source file:org.npr.android.news.DownloadDrawable.java
public static Drawable createFromUrl(String url) { InputStream data = null;/*from w w w. j a va2 s. c o m*/ Log.d(LOG_TAG, "Starting download"); HttpClient http = new DefaultHttpClient(); HttpGet method = new HttpGet(url); HttpResponse response = null; try { response = http.execute(method); data = response.getEntity().getContent(); } catch (ClientProtocolException e) { Log.e(LOG_TAG, "error downloading", e); } catch (IOException e) { Log.e(LOG_TAG, "error downloading", e); } catch (IllegalStateException e) { Log.e(LOG_TAG, "error downloading", e); } Log.d(LOG_TAG, "Download complete"); return Drawable.createFromStream(data, url); }
From source file:LogToFile.java
private static HttpResponse ExecuteRequest(HttpUriRequest request) { try {/*from www . j av a 2 s .c o m*/ HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = httpclient.execute(request); return response; } catch (Exception e) { Log.e("", e.getClass().getName() + "\n" + e.getMessage()); } return null; }
From source file:su.fmi.photoshareclient.remote.LoginHandler.java
public static boolean login(String username, char[] password) { try {//from w ww.j a va2s . co m ProjectProperties properties = new ProjectProperties(); HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost( "http://" + properties.get("socket") + properties.get("restEndpoint") + "/user/login"); StringEntity input = new StringEntity( "{\"username\":\"" + username + "\",\"password\":\"" + new String(password) + "\"}", ContentType.create("application/json")); post.setHeader("Content-Type", "application/json"); post.addHeader(BasicScheme.authenticate(new UsernamePasswordCredentials(username, new String(password)), "UTF-8", false)); post.setEntity(input); if (username.isEmpty() || password.length == 0) { return false; } HttpResponse response = (HttpResponse) client.execute(post); if (response.getStatusLine().getStatusCode() == 200) { String authString = username + ":" + new String(password); byte[] authEncBytes = Base64.encodeBase64(authString.getBytes()); authStringEncr = new String(authEncBytes); return true; } else { return false; } } catch (UnsupportedEncodingException ex) { Logger.getLogger(LoginGUI.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(LoginGUI.class.getName()).log(Level.SEVERE, null, ex); } return false; }
From source file:com.codingrhemes.steamsalesmobile.HttpThumbnails.java
public static Bitmap readPictureFromTheWeb(String URL) { HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(URL); Bitmap thePicture = null;/*ww w . j ava 2 s .co m*/ try { HttpResponse response = httpClient.execute(httpGet); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode == 200) { HttpEntity entity = response.getEntity(); InputStream inputStream = entity.getContent(); thePicture = BitmapFactory.decodeStream(inputStream); inputStream.close(); } else { Log.d("JSON", "Failed to download file"); } } catch (Exception e) { Log.d("HttpThumbnails", e.getLocalizedMessage()); } return thePicture; }