List of usage examples for org.apache.http.impl.client DefaultHttpClient DefaultHttpClient
public DefaultHttpClient()
From source file:com.squeezeday.marknadskoll.HttpHelper.java
private static HttpClient getClient() { return new DefaultHttpClient(); /*/*w w w . j a v a2 s . c o m*/ SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); HttpParams params = new BasicHttpParams(); SingleClientConnManager mgr = new SingleClientConnManager(params, schemeRegistry); return new DefaultHttpClient(mgr, params);*/ }
From source file:com.ssy.havefunweb.util.WeixinUtil.java
public static JSONObject doGetStr(String url) throws IOException { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); JSONObject jsonObject = null;/*from w w w .ja v a2s. co m*/ HttpResponse response = httpClient.execute(httpGet); HttpEntity entity = response.getEntity(); if (entity != null) { String result = EntityUtils.toString(entity, "UTF-8"); jsonObject = JSONObject.fromObject(result); } return jsonObject; }
From source file:edu.illinois.whereru.HTTPRequest.java
public static JSONObject makeHttpRequest(String urlString, String method, List<NameValuePair> params) { JSONObject jsonObject = null;// ww w . j ava2s .com try { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpResponse httpResponse; if (method.equals("POST")) { // init post HttpPost httpPost = new HttpPost(urlString); // set the resource to send httpPost.setEntity(new UrlEncodedFormEntity(params)); // send the request, retrieve response httpResponse = httpClient.execute(httpPost); } else { // GET method // formulate url String paramString = URLEncodedUtils.format(params, "utf-8"); urlString += "?" + paramString; // init GET HttpGet httpGet = new HttpGet(urlString); // send the request, retrieve response httpResponse = httpClient.execute(httpGet); } // retrieve content from the response HttpEntity httpEntity = httpResponse.getEntity(); InputStream is = httpEntity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); jsonObject = new JSONObject(sb.toString()); } catch (NullPointerException e) { } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return jsonObject; }
From source file:com.huguesjohnson.retroleague.util.RestInvoke.java
public static String invoke(String restUrl) throws Exception { String result = null;/* w w w.ja v a2 s . c o m*/ HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(restUrl); HttpResponse response = httpClient.execute(httpGet); HttpEntity httpEntity = response.getEntity(); if (httpEntity != null) { InputStream in = httpEntity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); StringBuffer temp = new StringBuffer(); String currentLine = null; while ((currentLine = reader.readLine()) != null) { temp.append(currentLine); } result = temp.toString(); in.close(); } return (result); }
From source file:com.splunk.shuttl.testutil.TUtilsEndToEnd.java
public static void callSlaveArchiveBucketEndpoint(String index, String bucketPath, String host, int shuttlPort) { HttpPost httpPost = EndpointUtils.createArchiveBucketPostRequest(host, shuttlPort, bucketPath, index); DefaultHttpClient httpClient = new DefaultHttpClient(); HttpResponse response = executeHttp(httpPost, httpClient); assertEquals(204, response.getStatusLine().getStatusCode()); }
From source file:org.prx.playerhater.util.PlaylistParser.java
public static Uri[] parsePlaylist(Uri uri) { try {//from w w w. j a v a 2s.c o m HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = httpclient.execute(new HttpHead(uri.toString())); Header contentType = response.getEntity().getContentType(); if (contentType != null) { String mimeType = contentType.getValue().split(";")[0].trim(); for (String plsMimeType : PLS_MIME_TYPES) { if (plsMimeType.equalsIgnoreCase(mimeType)) { return parsePls(uri); } } for (String m3uMimeType : M3U_MIME_TYPES) { if (m3uMimeType.equalsIgnoreCase(mimeType)) { return parseM3u(uri); } } } } catch (Exception e) { } return new Uri[] { uri }; }
From source file:br.unicamp.busfinder.ServerOperations.java
public static JSONArray getJSON(String site) { Log.d("Executing REquest", site); StringBuilder builder = new StringBuilder(); HttpGet get = new HttpGet(site); HttpClient client = new DefaultHttpClient(); HttpResponse response;//from w w w . j a v a2 s. co m try { response = client.execute(get); if (response.getStatusLine().getStatusCode() == 200) { HttpEntity entity = response.getEntity(); InputStream content = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(content)); String line; while ((line = reader.readLine()) != null) { builder.append(line); } } else { Log.e("ERRRO", "Failed to download file"); } Log.d("RESP:", builder.toString()); return new JSONArray(builder.toString()); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } return null; }
From source file:appserver.grupo5.http.java
public static Response Request(Method method, String url, String content, String contentType) { Response response;/*from ww w . ja v a 2s . com*/ try { HttpClient client = new DefaultHttpClient(); HttpUriRequest request; switch (method) { case GET: request = new HttpGet(url); break; case POST: request = new HttpPost(url); ((HttpPost) request).setEntity(new StringEntity(content)); break; case PUT: request = new HttpPut(url); ((HttpPut) request).setEntity(new StringEntity(content)); break; case DELETE: request = new HttpDeleteWithBody(url); ((HttpDeleteWithBody) request).setEntity(new StringEntity(content)); break; default: request = new HttpGet(url); break; } if (method != Method.GET) { request.setHeader("Content-type", contentType); } response = executeRequest(client, request); } catch (Exception e) { response = Response.status(400).entity(e.getMessage()).build(); } return response; }
From source file:com.tweetlanes.android.urlservice.ApiService.java
public static HttpResponse getRequest(String url, String debugName) { HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(); HttpResponse response = null;// w w w .java 2 s .c o m try { request.setURI(new URI(url)); //Log.d("tweetlanes url fetch", url); response = client.execute(request); //Log.d(TAG, debugName + " complete"); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return response; }
From source file:com.bigdata.rockstor.console.RockStorSender.java
public static HttpResp perform(HttpReq req) throws URISyntaxException, ClientProtocolException, IOException { HttpResp resp = null;// www .j a va 2 s . c o m HttpRequestBase request = buildHttpRequest(req); DefaultHttpClient client = new DefaultHttpClient(); HttpResponse response = client.execute(request); resp = buildHttpResponse(response); return resp; }