List of usage examples for org.apache.http.impl.client DefaultHttpClient DefaultHttpClient
public DefaultHttpClient()
From source file:com.unitedcoders.android.gpodroid.services.RSSService.java
private static String getImageUrlFromFeed(Context context, String url) { try {/*from w w w . j av a 2 s . c om*/ Document doc; DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); DefaultHttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(url); HttpResponse response = client.execute(request); doc = builder.parse(response.getEntity().getContent()); // return doc; // get Image NodeList item = doc.getElementsByTagName("channel"); Element el = (Element) item.item(0); String imageUrl; NodeList imagNode = el.getElementsByTagName("image"); if (imagNode != null) { Element ima = (Element) imagNode.item(0); if (ima != null) { NodeList urlNode = ima.getElementsByTagName("url"); if (urlNode == null || urlNode.getLength() < 1) imageUrl = null; else imageUrl = urlNode.item(0).getFirstChild().getNodeValue(); } else imageUrl = null; } else imageUrl = null; return imageUrl; } catch (IOException e) { return null; // The network probably died, just return null } catch (SAXException e) { // Problem parsing the XML, log and return nothing Log.e("NCRSS", "Error parsing XML", e); return null; } catch (Exception e) { // Anything else was probably another network problem, fail silently return null; } }
From source file:com.bjorsond.android.timeline.sync.ServerDeleter.java
private static void sendDeleteRequestTOGAEServer(String string, final HttpHost targetHost, final HttpDelete httpDelete) { Runnable sendRunnable = new Runnable() { public void run() { try { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpResponse response = httpClient.execute(targetHost, httpDelete); Log.v("Delete to GAE", Utilities.convertStreamToString(response.getEntity().getContent())); } catch (Exception ex) { ex.printStackTrace();//from w w w .ja va 2 s . co m } } }; Thread thread = new Thread(null, sendRunnable, "deleteToGAE"); thread.start(); }
From source file:com.quietlycoding.android.reader.util.api.Subscriptions.java
/** * This method queries Google Reader for the list of subscribed feeds. * /* w ww . ja v a2 s. co m*/ * @param sid * authentication code to pass along in a cookie. * @return arr returns a JSONArray of JSONObjects for each feed. * * The JSONObject returned by the service looks like this: id: this * is the feed url. title: this is the title of the feed. sortid: * this has not been figured out yet. firstitemsec: this has not * been figured out yet. */ public static JSONArray getSubscriptionList(String sid) { final DefaultHttpClient client = new DefaultHttpClient(); final HttpGet get = new HttpGet(SUB_URL + "/list?output=json"); final BasicClientCookie cookie = Authentication.buildCookie(sid); try { client.getCookieStore().addCookie(cookie); final HttpResponse response = client.execute(get); final HttpEntity respEntity = response.getEntity(); Log.d(TAG, "Response from server: " + response.getStatusLine()); final InputStream in = respEntity.getContent(); final BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line = ""; String arr = ""; while ((line = reader.readLine()) != null) { arr += line; } final JSONObject obj = new JSONObject(arr); final JSONArray array = obj.getJSONArray("subscriptions"); reader.close(); client.getConnectionManager().shutdown(); return array; } catch (final Exception e) { Log.d(TAG, "Exception caught:: " + e.toString()); return null; } }
From source file:gr.ntua.ivml.awareness.search.SearchServiceAccess.java
public SearchServiceAccess() { httpClient = new DefaultHttpClient(); }
From source file:br.com.estudogrupo.online.DicionarioOnline05.java
@Override public void run() { HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet("http://hashtoolkit.com/reverse-hash?hash=" + getRecebe()); HttpResponse response = null;// w ww . j a va 2s . co m try { response = client.execute(request); } catch (IOException ex) { Logger.getLogger(DicionarioOnline05.class.getName()).log(Level.SEVERE, null, ex); } // Get the response BufferedReader rd = null; try { rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); } catch (IOException ex) { Logger.getLogger(DicionarioOnline05.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalStateException ex) { Logger.getLogger(DicionarioOnline05.class.getName()).log(Level.SEVERE, null, ex); } String line = ""; try { while ((line = rd.readLine().trim()) != null) { if (line.startsWith("<span style=\"float: right;\"><a href=\"/generate-hash/?text=")) { String key = line.substring(58, 70); System.out.println("Senha : " + key.replaceAll("\"><span", "")); System.exit(0); } } } catch (IOException ex) { Logger.getLogger(DicionarioOnline05.class.getName()).log(Level.SEVERE, null, ex); } catch (NullPointerException e) { } }
From source file:com.devdungeon.simplejson.DecodeJson.java
public static String getJsonFromUrl(String url) { HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(url); httpget.setHeader("User-Agent", "Java Reddit Test Client 0.0.1"); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = null;/*ww w . jav a 2s . c om*/ try { responseBody = httpclient.execute(httpget, responseHandler); } catch (IOException ex) { ex.printStackTrace(); } httpclient.getConnectionManager().shutdown(); return responseBody; }
From source file:uk.ac.diamond.scisoft.feedback.FeedbackRequest.java
/** * Method used to submit a form data/file through HTTP to a GAE servlet * /*from w w w. j a v a2s .c o m*/ * @param email * @param to * @param name * @param subject * @param messageBody * @param attachmentFiles * @param monitor */ public static IStatus doRequest(String email, String to, String name, String subject, String messageBody, List<File> attachmentFiles, IProgressMonitor monitor) throws Exception { Status status = null; DefaultHttpClient httpclient = new DefaultHttpClient(); FeedbackProxy.init(); host = FeedbackProxy.getHost(); port = FeedbackProxy.getPort(); if (monitor.isCanceled()) return Status.CANCEL_STATUS; // if there is a proxy if (host != null) { HttpHost proxy = new HttpHost(host, port); httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } if (monitor.isCanceled()) return Status.CANCEL_STATUS; try { HttpPost httpost = new HttpPost(SERVLET_URL + SERVLET_NAME); MultipartEntity entity = new MultipartEntity(); entity.addPart("name", new StringBody(name)); entity.addPart("email", new StringBody(email)); entity.addPart("to", new StringBody(to)); entity.addPart("subject", new StringBody(subject)); entity.addPart("message", new StringBody(messageBody)); // add attachement files to the multipart entity for (int i = 0; i < attachmentFiles.size(); i++) { if (attachmentFiles.get(i) != null && attachmentFiles.get(i).exists()) entity.addPart("attachment" + i + ".html", new FileBody(attachmentFiles.get(i))); } if (monitor.isCanceled()) return Status.CANCEL_STATUS; httpost.setEntity(entity); // HttpPost post = new HttpPost("http://dawnsci-feedback.appspot.com/dawnfeedback?name=baha&email=baha@email.com&subject=thisisasubject&message=thisisthemessage"); HttpResponse response = httpclient.execute(httpost); if (monitor.isCanceled()) return Status.CANCEL_STATUS; final String reasonPhrase = response.getStatusLine().getReasonPhrase(); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == 200) { logger.debug("Status code 200"); status = new Status(IStatus.OK, "Feedback successfully sent", "Thank you for your contribution"); } else { logger.debug("Feedback email not sent - HTTP response: " + reasonPhrase); status = new Status(IStatus.WARNING, "Feedback not sent", "The response from the server is the following:\n" + reasonPhrase + "\nClick on OK to submit your feedback using the online feedback form available at http://dawnsci-feedback.appspot.com/"); } logger.debug("HTTP Response: " + response.getStatusLine()); } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); } return status; }
From source file:org.n52.sir.script.HTTPRequest.java
public String doGet(String s) throws ClientProtocolException, IOException { HttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet(s); HttpResponse resp = client.execute(get); StringBuilder builder = new StringBuilder(); String r = ""; BufferedReader reader = new BufferedReader(new InputStreamReader(resp.getEntity().getContent())); while ((r = reader.readLine()) != null) builder.append(r);/*from w w w .j a va2 s .co m*/ return builder.toString(); }
From source file:WSpatern.WorkFlow.java
public void getWorkFlow(String token, String id) { try {//ww w. j a v a 2 s .c om DefaultHttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet("https://documenta-dms.com/DMSWS/api/v1/flow/" + token + "/get/" + id); HttpResponse response = client.execute(get); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = ""; while ((line = rd.readLine()) != null) { System.out.println(line); parseXML(line); } } catch (IOException ex) { Logger.getLogger(ValidTokenWS.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.liferay.mobile.android.util.PortalVersionUtil.java
protected static int getBuilderNumberHeader(String url) throws IOException { HttpClient client = new DefaultHttpClient(); HttpHead head = new HttpHead(url); HttpResponse response = client.execute(head); Header portalHeader = response.getFirstHeader("Liferay-Portal"); if (portalHeader == null) { return PortalVersion.UNKNOWN; }/*w ww .ja v a 2 s .c om*/ String portalField = portalHeader.getValue(); int indexOfBuild = portalField.indexOf("Build"); if (indexOfBuild == -1) { return PortalVersion.UNKNOWN; } else { String buildNumber = portalField.substring(indexOfBuild + 6, indexOfBuild + 10); return Integer.valueOf(buildNumber); } }