List of usage examples for org.apache.http.impl.client DefaultHttpClient DefaultHttpClient
public DefaultHttpClient()
From source file:com.earth.places.utilities.JSONParser.java
public static JSONObject getJSONFromURL(String url) { try {//w w w . jav a 2s . c om HttpClient client = new DefaultHttpClient(); HttpResponse response = client.execute(new HttpGet(url)); if (response.getStatusLine().getStatusCode() == 200) { final String data = EntityUtils.toString(response.getEntity()); return new JSONObject(data); } } catch (Exception e) { Log.d(TAG, "No response from the server, where you have stored your json: " + e.getMessage()); } return null; }
From source file:org.terracotta.management.cli.rest.HttpServices.java
public static void initHttpClient() throws IOException, ClassNotFoundException { if (httpClient == null) { httpClient = new DefaultHttpClient(); //CookieStore cookieStore = (CookieStore) load("rest-client-cookies.bin"); //if (cookieStore != null) { // httpClient.setCookieStore(cookieStore); //}//from w ww . java 2s .c om } }
From source file:language_engine.HttpUtils.java
public static String doHttpGet(String url) { try {//from w w w .j a va 2 s . co m HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); HttpResponse resp = httpClient.execute(httpGet); return StreamUtil.readText(resp.getEntity().getContent(), "UTF-8"); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:HttpUtils.java
public static InputStream getData(String url) throws ClientProtocolException, IOException { HttpGet httpget = new HttpGet(url); HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = httpclient.execute(httpget); if (response.getStatusLine().getStatusCode() != 200) return null; HttpEntity entity = response.getEntity(); if (entity == null) { return null; }//from w w w . j a va2 s. c o m InputStream instream = entity.getContent(); return instream; }
From source file:Extras.JSON.java
public static HttpResponse request(String URL) { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(URL); HttpResponse response = null;// ww w .j ava2s . c om try { response = httpclient.execute(httppost); } catch (Exception e) { } return response; }
From source file:Main.java
public static boolean getkeepaliveinfo() { String baseUrl = "http://10.6.8.2/cgi-bin/keeplive?"; try {//from ww w. j a v a 2s . co m HttpGet getMethod = new HttpGet(baseUrl); getMethod.addHeader("Accept", "*/*"); //getMethod.addHeader("Accept-Language", "zh-cn"); //getMethod.addHeader("Referer", "http://202.117.2.41/index.html"); //getMethod.addHeader("Content-Type", "application/x-www-form-urlencoded"); //getMethod.addHeader("Accept-Encoding", "gzip, deflate"); //getMethod.addHeader("User-Agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)"); getMethod.addHeader("Host", "10.6.8.2"); //getMethod.addHeader("DNT", "1"); HttpClient httpClient = new DefaultHttpClient(); HttpResponse response = httpClient.execute(getMethod); Log.i(TAG, "Sending message....."); HttpEntity httpEntity = response.getEntity(); if (response.getStatusLine().getStatusCode() == 200) { String message = EntityUtils.toString(httpEntity); if (httpEntity == null || message.compareTo("error") == 0) { Log.i(TAG, "Get keepalive info failed!!!message=" + message); return false; } else { Log.i(TAG, "Get keepalive info succeed!!!message=" + message); return true; } } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Log.i(TAG, "Get keepalive info failed!!!"); return false; }
From source file:Main.java
public static boolean logout() { String baseUrl = "http://10.6.8.2/cgi-bin/srun_portal?action=logout&ac_id=1"; try {/*w w w . j ava 2 s. c o m*/ HttpGet getMethod = new HttpGet(baseUrl); getMethod.addHeader("Accept", "*/*"); //getMethod.addHeader("Accept-Language", "zh-cn"); //getMethod.addHeader("Referer", "http://202.117.2.41/index.html"); //getMethod.addHeader("Content-Type", "application/x-www-form-urlencoded"); //getMethod.addHeader("Accept-Encoding", "gzip, deflate"); //getMethod.addHeader("User-Agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)"); getMethod.addHeader("Host", "10.6.8.2"); //getMethod.addHeader("DNT", "1"); HttpClient httpClient = new DefaultHttpClient(); HttpResponse response = httpClient.execute(getMethod); Log.i(TAG, "Sending message....."); HttpEntity httpEntity = response.getEntity(); if (response.getStatusLine().getStatusCode() == 200) { String message = EntityUtils.toString(httpEntity); Log.i(TAG, "Logout succeed!!! message=" + message); return true; } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Log.i(TAG, "Logout failed!!!"); return false; }
From source file:edu.usu.sdl.opencatalog.service.query.SolrService.java
public static void init() { String url = PropertiesManager.getValue("SOLR_BASE_ADDRESS", "http://localhost:8983/solr/") + CORE_EXAMPLE; exampleServer = new HttpSolrServer(url, new DefaultHttpClient()); }
From source file:de.vanita5.twittnuker.util.HttpClientFactory.java
public static synchronized DefaultHttpClient getThreadSafeClient() { if (client != null) { return client; }/*from w w w . j av a2s.c o m*/ client = new DefaultHttpClient(); ClientConnectionManager manager = client.getConnectionManager(); HttpParams params = client.getParams(); client = new DefaultHttpClient(new ThreadSafeClientConnManager(params, manager.getSchemeRegistry()), params); return client; }
From source file:com.android.dialer.lookup.LookupUtils.java
public static String httpGet(HttpGet request) throws IOException { HttpClient client = new DefaultHttpClient(); request.setHeader("User-Agent", USER_AGENT); HttpResponse response = client.execute(request); int status = response.getStatusLine().getStatusCode(); // Android's org.apache.http doesn't have the RedirectStrategy class if (status == HttpStatus.SC_MOVED_PERMANENTLY || status == HttpStatus.SC_MOVED_TEMPORARILY) { Header[] headers = response.getHeaders("Location"); if (headers != null && headers.length != 0) { HttpGet newGet = new HttpGet(headers[headers.length - 1].getValue()); for (Header header : request.getAllHeaders()) { newGet.addHeader(header); }/* w ww. j ava2 s . c o m*/ return httpGet(newGet); } else { throw new IOException("Empty redirection header"); } } if (status != HttpStatus.SC_OK) { throw new IOException("HTTP failure (status " + status + ")"); } return EntityUtils.toString(response.getEntity()); }