List of usage examples for org.apache.http.impl.client DefaultHttpClient execute
public CloseableHttpResponse execute(final HttpUriRequest request) throws IOException, ClientProtocolException
From source file:att.jaxrs.client.Content_tag.java
public static String deleteContent_tag(long content_id, long tag_id) { List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("content_id", Long.toString(content_id))); urlParameters.add(new BasicNameValuePair("tag_id", Long.toString(tag_id))); String resultStr = ""; try {//from ww w. j a v a 2 s . c om DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost post = new HttpPost(Constants.DELETE_CONTENT_TAG_RESOURCE); post.setEntity(new UrlEncodedFormEntity(urlParameters)); HttpResponse result = httpClient.execute(post); System.out.println(Constants.RESPONSE_STATUS_CODE + result); resultStr = Util.getStringFromInputStream(result.getEntity().getContent()); System.out.println(Constants.RESPONSE_BODY + resultStr); } catch (Exception e) { System.out.println(e.getMessage()); } return resultStr; }
From source file:att.jaxrs.client.Tag.java
public static long getExistingRecord(String tag_name) { List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("tag_name", tag_name)); HttpResponse result;// ww w . java 2s. co m String resultStr; TagCollection tagCollection = new TagCollection(); try { System.out.println("invoking last added: " + tag_name); DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost post = new HttpPost(Constants.SELECT_LAST_ADDED_TAG_RESOURCE); post.setEntity(new UrlEncodedFormEntity(urlParameters)); result = httpClient.execute(post); System.out.println(Constants.RESPONSE_STATUS_CODE + result); resultStr = Util.getStringFromInputStream(result); tagCollection = Marshal.unmarshal(TagCollection.class, resultStr); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } if (null != tagCollection.getTag()) { return tagCollection.getTag()[0].getTag_id(); } return -1L; }
From source file:com.bukanir.android.utils.Utils.java
public static InputStream getURL(String url) { URI uri;//from w w w .ja va2s. com InputStream data = null; DefaultHttpClient httpClient = new DefaultHttpClient(); try { uri = new URI(url); HttpGet method = new HttpGet(uri); HttpResponse response = httpClient.execute(method); data = response.getEntity().getContent(); } catch (Exception e) { } return data; }
From source file:org.androidnerds.reader.util.api.Authentication.java
/** * This method returns back to the caller a proper authentication token to use with * the other API calls to Google Reader. * * @param user - the Google username//from ww w .ja v a 2 s. co m * @param pass - the Google password * @return sid - the returned authentication token for use with the API. * */ public static String getAuthToken(String user, String pass) { NameValuePair username = new BasicNameValuePair("Email", user); NameValuePair password = new BasicNameValuePair("Passwd", pass); NameValuePair service = new BasicNameValuePair("service", "reader"); List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(username); pairs.add(password); pairs.add(service); try { DefaultHttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(AUTH_URL); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairs); post.setEntity(entity); HttpResponse response = client.execute(post); HttpEntity respEntity = response.getEntity(); Log.d(TAG, "Server Response: " + response.getStatusLine()); InputStream in = respEntity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line = null; String result = null; while ((line = reader.readLine()) != null) { if (line.startsWith("SID")) { result = line.substring(line.indexOf("=") + 1); } } reader.close(); client.getConnectionManager().shutdown(); return result; } catch (Exception e) { Log.d(TAG, "Exception caught:: " + e.toString()); return null; } }
From source file:att.jaxrs.client.Content.java
public static String deleteContent(long content_id) { List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("content_id", Long.toString(content_id))); String resultStr = ""; try {/*from ww w.j av a 2 s. co m*/ DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost post = new HttpPost(Constants.DELETE_CONTENT_RESOURCE); post.setEntity(new UrlEncodedFormEntity(urlParameters)); HttpResponse result = httpClient.execute(post); System.out.println(Constants.RESPONSE_STATUS_CODE + result); resultStr = Util.getStringFromInputStream(result.getEntity().getContent()); System.out.println(Constants.RESPONSE_BODY + resultStr); } catch (Exception e) { System.out.println(e.getMessage()); } return resultStr; }
From source file:att.jaxrs.client.Content.java
public static String addContent(Content content) { List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("content_id", content.getContent_id().toString())); urlParameters.add(new BasicNameValuePair("level", content.getLevel())); urlParameters.add(new BasicNameValuePair("presenter", content.getPresenter())); urlParameters.add(new BasicNameValuePair("reads", content.getReads())); String resultStr = ""; try {/*from w w w . j a v a2s . c om*/ DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost post = new HttpPost(Constants.INSERT_CONTENT_RESOURCE); post.setEntity(new UrlEncodedFormEntity(urlParameters)); HttpResponse result = httpClient.execute(post); System.out.println(Constants.RESPONSE_STATUS_CODE + result); resultStr = Util.getStringFromInputStream(result.getEntity().getContent()); System.out.println(Constants.RESPONSE_BODY + resultStr); } catch (Exception e) { System.out.println(e.getMessage()); } return resultStr; }
From source file:att.jaxrs.client.Content.java
public static String updateContent(Content content) { List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("content_id", content.getContent_id().toString())); urlParameters.add(new BasicNameValuePair("level", content.getLevel())); urlParameters.add(new BasicNameValuePair("presenter", content.getPresenter())); urlParameters.add(new BasicNameValuePair("reads", content.getReads())); String resultStr = ""; try {//from ww w. ja va2s. c o m DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost post = new HttpPost(Constants.UPDATE_CONTENT_RESOURCE); post.setEntity(new UrlEncodedFormEntity(urlParameters)); HttpResponse result = httpClient.execute(post); System.out.println(Constants.RESPONSE_STATUS_CODE + result); resultStr = Util.getStringFromInputStream(result.getEntity().getContent()); System.out.println(Constants.RESPONSE_BODY + resultStr); } catch (Exception e) { System.out.println(e.getMessage()); } return resultStr; }
From source file:neembuu.release1.settings.OnlineSettingImpl.java
public static String getRaw(String... p) { //Get the version.xml and read the version value. HttpParams params = new BasicHttpParams(); params.setParameter("http.useragent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6"); DefaultHttpClient httpclient = new DefaultHttpClient(params); String pth = ""; for (String p_ele : p) { pth = pth + "/" + p_ele; }// ww w.ja v a 2s . co m HttpGet httpget = new HttpGet("http://neembuu.sourceforge.net" + pth); LoggerUtil.L().log(Level.INFO, "Getting online setting ...{0}", p); try { HttpResponse response = httpclient.execute(httpget); String respxml = EntityUtils.toString(response.getEntity()); return respxml; } catch (Exception ex) { LoggerUtil.L().log(Level.INFO, "Exception while getting resource " + p, ex); } return null; }
From source file:no.uib.tools.OnthologyHttpClient.java
public static List<String> getTermDescendants(String onthologyName, String term, String relation) { List<String> result = new ArrayList<>(); String queryContent = ""; onthologySize = getOntologySize(onthologyName); String uri = createUri(onthologyName, term, relation); //BufferedReader br = getContentBufferedReader(uri); //String queryContent = convertBufferedReader(br); DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet getRequest = new HttpGet(uri); getRequest.addHeader("accept", "application/json"); HttpResponse response;//from w w w .j a v a 2 s .c o m try { response = httpClient.execute(getRequest); if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException("Failed to get the PSIMOD onthology : HTTP error code : " + response.getStatusLine().getStatusCode()); } BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); String line; FileWriter fw = new FileWriter("./mod.json"); while ((line = br.readLine()) != null) { fw.write(line); queryContent += line; } fw.close(); httpClient.getConnectionManager().shutdown(); char c; int matched = 0; String mod = ""; int pos = 0; while (pos < queryContent.length()) { c = queryContent.charAt(pos); pos++; if (c == pattern.charAt(matched)) { matched++; if (matched == pattern.length()) { for (int I = 0; I < 5; I++) { mod += queryContent.charAt(pos); pos++; } result.add(mod); mod = ""; matched = 0; } } else { matched = 0; } } } catch (IOException ex) { Logger.getLogger(OnthologyHttpClient.class.getName()).log(Level.SEVERE, null, ex); } return result; }
From source file:com.quietlycoding.android.reader.util.api.Authentication.java
/** * This method returns back to the caller a proper authentication token to * use with the other API calls to Google Reader. * //from w ww . j a v a 2s .co m * @param user * - the Google username * @param pass * - the Google password * @return sid - the returned authentication token for use with the API. * */ public static String getAuthToken(String user, String pass) { final NameValuePair username = new BasicNameValuePair("Email", user); final NameValuePair password = new BasicNameValuePair("Passwd", pass); final NameValuePair service = new BasicNameValuePair("service", "reader"); final List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(username); pairs.add(password); pairs.add(service); try { final DefaultHttpClient client = new DefaultHttpClient(); final HttpPost post = new HttpPost(AUTH_URL); final UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairs); post.setEntity(entity); final HttpResponse response = client.execute(post); final HttpEntity respEntity = response.getEntity(); Log.d(TAG, "Server Response: " + response.getStatusLine()); final InputStream in = respEntity.getContent(); final BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line = null; String result = null; while ((line = reader.readLine()) != null) { if (line.startsWith("SID")) { result = line.substring(line.indexOf("=") + 1); } } reader.close(); client.getConnectionManager().shutdown(); return result; } catch (final Exception e) { Log.d(TAG, "Exception caught:: " + e.toString()); return null; } }