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.CaptureAdminResources.java
public static HttpResponse recording(TrustedHttpClient client, String id) { return client.execute(new HttpGet(getServiceUrl() + "recordings/" + id)); }
From source file:com.appassit.http.ApiRequestFactory.java
/** * ?Market API HttpReqeust/*from w ww . j av a 2 s. c o m*/ */ public static HttpUriRequest getRequest(String url, RequestMethod requestMethod, ArrayList<BasicNameValuePair> cv) throws IOException { if (requestMethod == RequestMethod.GET) { String finalUrl = getGetRequestUrl(url, cv); HttpGet httpGet = new HttpGet(finalUrl); return httpGet; } else if (requestMethod == RequestMethod.POST) { HttpEntity entity = getPostRequestEntity(cv); HttpPost request = new HttpPost(url); request.setEntity(entity); return request; } else { return null; } }
From source file:edu.lternet.pasta.client.HttpGetFactory.java
/** * Manufactures an HttpGet object, adding auth-token and robot cookies as appropriate. * /*from www . ja v a 2 s .c o m*/ * @param url The URL of the request * @param token Auth-token string, possibly null * @param robot Robot string, possibly null * @return An Httpget object */ public static HttpGet makeHttpGet(String url, String token, String robot) { HttpGet httpGet = new HttpGet(url); if (token != null) { httpGet.setHeader("Cookie", "auth-token=" + token); } if (robot != null) { String b64Robot = new String(Base64.encodeBase64(robot.getBytes())); httpGet.setHeader("Cookie", "robot=" + b64Robot); } return httpGet; }
From source file:org.opencastproject.remotetest.server.resource.WorkflowResources.java
/** * //w w w .j a v a 2 s . c om * @param format Response format: xml or json * */ public static HttpResponse definitions(TrustedHttpClient client, String format) throws Exception { return client.execute(new HttpGet(getServiceUrl() + "definitions." + format.toLowerCase())); }
From source file:Main.java
static public String doHttpGet(String url, HashMap<String, String> map) { HttpClient client = new DefaultHttpClient(); HttpConnectionParams.setConnectionTimeout(client.getParams(), TIMEOUT); HttpConnectionParams.setSoTimeout(client.getParams(), TIMEOUT); ConnManagerParams.setTimeout(client.getParams(), TIMEOUT); String result = "ERROR"; if (null != map) { int i = 0; for (Map.Entry<String, String> entry : map.entrySet()) { if (i == 0) { url = url + "?" + entry.getKey() + "=" + entry.getValue(); } else { url = url + "&" + entry.getKey() + "=" + entry.getValue(); }//from w w w . j a v a 2 s . c o m i++; } } HttpGet get = new HttpGet(url); get.setHeaders(headers); try { HttpResponse response = client.execute(get); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { // setCookie(response); result = EntityUtils.toString(response.getEntity(), "UTF-8"); } else { result = EntityUtils.toString(response.getEntity(), "UTF-8") + response.getStatusLine().getStatusCode() + "ERROR"; } if (result != null) { if (result.startsWith("\ufeff")) { result = result.substring(1); } } } catch (ConnectTimeoutException e) { result = "TIMEOUTERROR"; } catch (Exception e) { result = "OTHERERROR"; e.printStackTrace(); } return result; }
From source file:com.mmj.app.common.util.SpiderHtmlUtils.java
/** * ?URLhtml?/* www . j av a 2s. co m*/ * * @param url * @return */ public static String getHtmlByUrl(String url) { if (StringUtils.isEmpty(url)) { return null; } String html = null; HttpClient httpClient = new DefaultHttpClient();// httpClient HttpUriRequest httpget = new HttpGet(url);// get?URL httpget.setHeader("Connection", "keep-alive"); httpget.setHeader("Referer", "http://www.baidu.com"); httpget.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); httpget.setHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36"); try { HttpResponse responce = httpClient.execute(httpget);// responce int responseCode = responce.getStatusLine().getStatusCode();// ? if (responseCode == HttpStatus.SC_OK || responseCode == HttpStatus.SC_MOVED_PERMANENTLY || responseCode == HttpStatus.SC_MOVED_TEMPORARILY) {// 200 ? // HttpEntity entity = responce.getEntity(); if (entity != null) { html = EntityUtils.toString((org.apache.http.HttpEntity) entity);// html?? } } } catch (Exception e) { logger.error("SpiderHtmlUtils:getHtmlByUrl sprider url={} error!!!", url); } finally { httpClient.getConnectionManager().shutdown(); } return html; }
From source file:com.codingrhemes.steamsalesmobile.JSON.java
public static String readJSONFeed(String URL) { StringBuilder stringBuilder = new StringBuilder(); HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(URL); try {//from w w w .j a v a2 s . c om HttpResponse response = httpClient.execute(httpGet); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode == 200) { HttpEntity entity = response.getEntity(); InputStream inputStream = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); String line; while ((line = reader.readLine()) != null) { stringBuilder.append(line); } inputStream.close(); } else { Log.d("JSON", "Failed to download file"); } } catch (Exception e) { Log.d("readJSONFeed", e.getLocalizedMessage()); } return stringBuilder.toString(); }
From source file:email.mandrill.MandrillApiHandler.java
public static Map<String, Object> getEmailDetails(String mandrillEmailId) throws URISyntaxException, IOException { Map<String, Object> emailDetails = new HashMap<>(); HttpClient httpclient = HttpClients.createDefault(); HttpGet httpGet = new HttpGet("https://mandrillapp.com/api/1.0/messages/info.json"); URI uri = new URIBuilder(httpGet.getURI()).addParameter("key", SendEmail.MANDRILL_KEY) .addParameter("id", mandrillEmailId).build(); logger.info("Getting Email details: " + uri.toString()); Gson gson = new Gson(); httpGet.setURI(uri);//from w w w. j a v a 2 s . com //Execute and get the response. HttpResponse response = httpclient.execute(httpGet); HttpEntity responseEntity = response.getEntity(); if (responseEntity != null) { String jsonContent = EntityUtils.toString(responseEntity); logger.info(jsonContent); // Create a Reader from String Reader stringReader = new StringReader(jsonContent); // Pass the string reader to JsonReader constructor JsonReader reader = new JsonReader(stringReader); reader.setLenient(true); Map<String, Object> mandrillEmailDetails = gson.fromJson(reader, Map.class); emailDetails.put("sent_on", mandrillEmailDetails.get("ts")); emailDetails.put("mandrill_id", mandrillEmailDetails.get("_id")); emailDetails.put("email_state", mandrillEmailDetails.get("state")); emailDetails.put("subject", mandrillEmailDetails.get("subject")); emailDetails.put("email", mandrillEmailDetails.get("email")); emailDetails.put("tags", mandrillEmailDetails.get("tags")); emailDetails.put("opens", mandrillEmailDetails.get("opens")); emailDetails.put("clicks", mandrillEmailDetails.get("clicks")); emailDetails.put("sender", mandrillEmailDetails.get("sender")); } return emailDetails; }
From source file:org.opencastproject.remotetest.server.resource.AdminResources.java
public static HttpResponse recordingsProcessing(TrustedHttpClient client) { return client.execute(new HttpGet(getServiceUrl() + "recordings/capturing")); }
From source file:com.rogiel.httpchannel.util.HttpClientUtils.java
public static HttpResponse get(HttpClient client, String uri) throws IOException { return client.execute(new HttpGet(uri)); }