List of usage examples for org.apache.http.client.methods HttpGet HttpGet
public HttpGet(final String uri)
From source file:org.opencastproject.remotetest.server.resource.FilesResources.java
public static HttpResponse getFile(TrustedHttpClient client, String mediaPackageID, String mediaPackageElementID) throws Exception { return client.execute( new HttpGet(getServiceUrl() + "mediapackage/" + mediaPackageID + '/' + mediaPackageElementID)); }
From source file:com.plnyyanks.frcnotebook.datafeed.GET_Request.java
public static String getWebData(String url, boolean tbaheader) { InputStream is = null;/* ww w . j a v a 2 s. c o m*/ String result = ""; // HTTP try { HttpClient httpclient = new DefaultHttpClient(); // for port 80 requests! HttpGet httpget = new HttpGet(url); if (tbaheader) httpget.addHeader(Constants.TBA_HEADER, Constants.TBA_HEADER_TEXT); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); is = entity.getContent(); } catch (Exception e) { Log.e(Constants.LOG_TAG, e.toString()); return null; } // Read response to string try { BufferedReader reader = new BufferedReader(new InputStreamReader(is, "utf-8"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); result = sb.toString(); } catch (Exception e) { Log.e(Constants.LOG_TAG, e.toString()); return null; } return result; }
From source file:com.alibaba.flink.utils.MetricsMonitor.java
public static Map httpResponse(String url) { Map ret;/* w w w . j ava 2s . c o m*/ try { 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( "Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); } String data = EntityUtils.toString(response.getEntity()); ret = (Map) Utils.from_json(data); httpClient.getConnectionManager().shutdown(); } catch (IOException e) { ret = errorMsg(e.getMessage()); } return ret; }
From source file:de.fmaul.android.cmis.utils.HttpUtils.java
public static HttpResponse getWebRessource(String url, String user, String password) throws IOException, ClientProtocolException { HttpGet get = new HttpGet(url); HttpClient client = createClient(user, password); return client.execute(get); }
From source file:com.fpmislata.clientejson.ClienteProductoTest.java
private static List<Producto> getListProducto(String url) throws IOException { // Crea el cliente para realizar la conexion DefaultHttpClient httpClient = new DefaultHttpClient(); // Crea el mtodo con el que va a realizar la operacion HttpGet httpGet = new HttpGet(url); // Aade las cabeceras al metodo httpGet.addHeader("accept", "application/json; charset=UTF-8"); httpGet.addHeader("Content-type", "application/json; charset=UTF-8"); // Invocamos el servicio rest y obtenemos la respuesta HttpResponse response = httpClient.execute(httpGet); // Obtenemos un objeto String como respuesta del response String lista = readObject(response); // Creamos el objeto Gson que parsear los objetos a JSON, excluyendo los que no tienen la anotacion @Expose Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); // Creamos el tipo generico que nos va a permitir devolver la lista a partir del JSON que esta en el String Type type = new TypeToken<List<Producto>>() { }.getType();//from w ww . j a v a 2s. c o m // Parseamos el String lista a un objeto con el gson, devolviendo as un objeto List<Categoria> return gson.fromJson(lista, type); }
From source file:it.agileday.utils.HttpRestUtil.java
public static JSONObject httpGetJsonObject(String uri) { try {//from w w w. j ava 2s . c o m HttpGet httpGetRequest = new HttpGet(uri); httpGetRequest.setHeader("Accept", "application/json"); httpGetRequest.setHeader("Accept-Encoding", "gzip"); HttpResponse response = new DefaultHttpClient().execute(httpGetRequest); HttpEntity entity = response.getEntity(); JSONObject ret = null; if (entity != null) { InputStream stream = entity.getContent(); try { if (HttpRestUtil.isGzipEncoded(response)) { stream = new GZIPInputStream(stream); } String str = HttpRestUtil.convertStreamToString(stream); ret = new JSONObject(str); } finally { stream.close(); } } return ret; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:kr.pe.javarss.mybus.task.GBusPageParser.java
public static InputStream getPageInputStream(String url) throws IOException { // : 30 ? HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(params, CONNECTION_TIMEOUT); HttpClient hc = new DefaultHttpClient(params); HttpResponse res = hc.execute(new HttpGet(url)); if (res.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { throw new UnknownServiceException(); }//from ww w .java 2 s . co m return res.getEntity().getContent(); }
From source file:com.ecofactor.qa.automation.util.HttpsUtil.java
/** * Gets the./* ww w . ja v a 2 s. co m*/ * @param url the url * @return the https response */ public static String get(String url, Map<String, String> params, int expectedStatus) { String content = null; HttpGet request = new HttpGet(url); URIBuilder builder = new URIBuilder(request.getURI()); if (params != null) { Set<String> keys = params.keySet(); for (String key : keys) { builder.addParameter(key, params.get(key)); } } try { request.setURI(builder.build()); DriverConfig.setLogString("URL " + request.getURI().toString(), true); driver.navigate().to(request.getURI().toString()); tinyWait(); content = driver.findElement(By.tagName("Body")).getText(); DriverConfig.setLogString("Content: " + content, true); } catch (Exception e) { LOGGER.error(e.getMessage()); } finally { request.releaseConnection(); } return content; }
From source file:org.openinfinity.cloud.util.http.HttpHelper.java
public static String executeHttpRequest(HttpClient client, String url) { HttpUriRequest request = new HttpGet(url); try {/*from ww w .j ava 2 s.co m*/ HttpResponse response = client.execute(request); int status = response.getStatusLine().getStatusCode(); if (status >= 200 && status < 300) { HttpEntity entity = response.getEntity(); return entity != null ? EntityUtils.toString(entity) : null; } } catch (ClientProtocolException e) { LOG.warn(EXCEPTION_WHILE_EXECUTING_HTTP_REQUEST + "----" + e.getMessage()); } catch (IOException e) { LOG.warn(EXCEPTION_WHILE_EXECUTING_HTTP_REQUEST + "----" + e.getMessage()); } catch (Exception e) { LOG.warn(EXCEPTION_WHILE_EXECUTING_HTTP_REQUEST + "----" + e.getMessage()); } return null; }
From source file:geert.stef.sm.beheerautokm.AddRitTask.java
public static HttpResponse hitUrl(String url) { try {/* ww w. j av a 2s. c o m*/ HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = httpclient.execute(new HttpGet(url)); return response; } catch (Exception e) { //Log.("[GET REQUEST]", "Network exception", e); return null; } }