List of usage examples for org.apache.http.client HttpClient execute
HttpResponse execute(HttpUriRequest request) throws IOException, ClientProtocolException;
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 ww w. jav a 2 s.c om*/ InputStream instream = entity.getContent(); return instream; }
From source file:HttpUtils.java
public static void testUrl(String url) throws ClientProtocolException, IOException { HttpHead head = new HttpHead(url); HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = httpclient.execute(head); StatusLine status = response.getStatusLine(); if (status.getStatusCode() == 404) { throw new FileNotFoundException(); }/*from www . j a v a 2 s.co m*/ if (status.getStatusCode() != 200) { throw new RuntimeException( "Could not get URL: " + status.getStatusCode() + ": " + status.getReasonPhrase()); } }
From source file:getopendata.HttpUtils.java
public static HttpResponse httpGet(String url) throws IOException { HttpClient httpClient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(url); HttpResponse response = httpClient.execute(httpget); return response; }
From source file:org.apache.hyracks.tests.integration.TestUtil.java
static InputStream httpGetAsInputStream(URI uri) throws URISyntaxException, IOException { HttpClient client = HttpClients.createMinimal(); HttpResponse response = client.execute(new HttpGet(uri)); return response.getEntity().getContent(); }
From source file:Main.java
public static String get(String url) throws Exception { HttpClient client = getHttpCilent(); HttpGet get = new HttpGet(url); HttpResponse response = client.execute(get); BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String resStr = ""; for (String s = reader.readLine(); s != null; s = reader.readLine()) { resStr += s;/*from w ww . j a va 2s .c om*/ } return resStr; }
From source file:com.earth.places.utilities.JSONParser.java
public static JSONObject getJSONFromURL(String url) { try {//w w w . j av a2 s . co m 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:Main.java
/** * fetch JSONArray from given url, must be called on worker thread * @param url//from w w w . ja v a2 s . c o m * @return * @throws JSONException * @throws IOException */ public static JSONArray getRemoteJsonArray(String url) throws JSONException, IOException { HttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet(url); HttpResponse response = client.execute(get); BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuilder builder = new StringBuilder(); for (String s = reader.readLine(); s != null; s = reader.readLine()) { builder.append(s); } return new JSONArray(builder.toString()); }
From source file:Main.java
public static String getJson(String url) throws ClientProtocolException, IOException, InterruptedException { StringBuilder builder = new StringBuilder(); HttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); HttpResponse response = client.execute(httpGet); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode == 200) { HttpEntity entity = response.getEntity(); InputStream content = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(content)); String line;/*from ww w.j a v a2 s.co m*/ while ((line = reader.readLine()) != null) builder.append(line); } return builder.toString(); }
From source file:de.avanux.android.livetracker2.HttpUtil.java
private static HttpResponse executeMethod(HttpRequestBase method) throws ClientProtocolException, IOException { HttpResponse response = null;//from w ww .j a va 2 s . c om HttpClient client = new DefaultHttpClient(); response = client.execute(method); Log.d(TAG, "executeMethod=" + response.getStatusLine()); return response; }
From source file:com.rogiel.httpchannel.util.HttpClientUtils.java
public static String execute(HttpClient client, HttpUriRequest request) throws IOException { return toString(client.execute(request)); }