Example usage for org.apache.http.impl.client DefaultHttpClient DefaultHttpClient

List of usage examples for org.apache.http.impl.client DefaultHttpClient DefaultHttpClient

Introduction

In this page you can find the example usage for org.apache.http.impl.client DefaultHttpClient DefaultHttpClient.

Prototype

public DefaultHttpClient() 

Source Link

Usage

From source file:fichiercentraltheses.PersonXMLCaller.java

public String callForXMLResponse() throws URISyntaxException, IOException {
    HttpClient httpclient = new DefaultHttpClient();

    URIBuilder builder = new URIBuilder();
    builder.setScheme("http").setHost("www.theses.fr").setPath("/personnes/").setParameter("q", "levallois")
            .setParameter("format", "xml");

    URI uri = builder.build();/*ww  w . j  av a 2s  .  com*/
    HttpGet httpget = new HttpGet(uri);
    //        HttpGet httpget = new HttpGet("http://ws.seloger.com/search.xml?ci=690381,690382,690383,690387&idqfix=1&idtt=2&idtypebien=1&tri=d_dt_crea");

    HttpResponse response = httpclient.execute(httpget);
    HttpEntity entity = response.getEntity();
    if (entity == null) {
        System.out.println("empty response to API call");
    }
    String responseString = EntityUtils.toString(entity);
    System.out.println(responseString);
    return responseString;
}

From source file:com.locadz.HttpClientFactory.java

/**
 * Get a client instance. <br/>//  w w  w.j  av a2s. c  om
 * Note: You should not assign the instance to a class variable.
 * @return a HttpClient instance.
 */
public static final HttpClient getInstance() {

    ReentrantReadWriteLock.ReadLock readLock = lock.readLock();

    try {
        readLock.lock();
        HttpClient httpClient = instance.get();
        if (httpClient == null) {
            readLock.unlock();
            lock.writeLock().lock();

            httpClient = instance.get();
            if (httpClient == null) {
                httpClient = new DefaultHttpClient();
                instance = new SoftReference<HttpClient>(httpClient);
            }
            readLock.lock();
            lock.writeLock().unlock();
        }
        return httpClient;

    } finally {
        readLock.unlock();
    }
}

From source file:es.ugr.swad.swadroid.webservices.RestEasy.java

public static HttpResponse doPost(String url, JSONObject c) throws ClientProtocolException, IOException {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost request = new HttpPost(url);
    StringEntity s = new StringEntity(c.toString());
    s.setContentEncoding("UTF-8");
    s.setContentType("application/json");

    request.setEntity(s);//from w w w .  j  ava2  s.c o m
    request.addHeader("accept", "application/json");

    return httpclient.execute(request);
}

From source file:CB_Core.Api.CB_Api.java

/**
 * Gibt die bei Team-Cachebox.de hinterlegte GC Auth url zurck
 * //  w ww .j a  v a 2 s . c  o m
 * @param staging
 *            Config.settings.StagingAPI.getValue()
 * @return String
 */
public static String getGcAuthUrl() {
    String result = "";

    try {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(
                CB_Core_Settings.StagingAPI.getValue() ? CB_API_URL_GET_URLS_Staging : CB_API_URL_GET_URLS);

        httppost.setHeader("Accept", "application/json");
        httppost.setHeader("Content-type", "application/json");

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);

        BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        String line = "";
        while ((line = rd.readLine()) != null) {
            result += line + "\n";
        }

        try
        // Parse JSON Result
        {
            JSONTokener tokener = new JSONTokener(result);
            JSONObject json = (JSONObject) tokener.nextValue();
            if (CB_Core_Settings.StagingAPI.getValue())
                return json.getString("GcAuth_ACB_Staging");
            return json.getString("GcAuth_ACB");

        } catch (JSONException e) {
            e.printStackTrace();
        }

    } catch (Exception ex) {
        ex.printStackTrace();
        return "";
    }
    return "";
}

From source file:at.uni_salzburg.cs.ckgroup.cscpp.utils.HttpQueryUtils.java

public static String simpleQuery(String url) throws IOException {

    HttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet(url);
    HttpResponse response;/*from   ww w.  j ava 2  s  .c  om*/

    response = httpclient.execute(httpget);
    ByteArrayOutputStream bo = new ByteArrayOutputStream();

    HttpEntity entity = response.getEntity();
    if (entity != null) {
        InputStream instream = entity.getContent();
        int l;
        byte[] tmp = new byte[2048];
        while ((l = instream.read(tmp)) != -1) {
            bo.write(tmp, 0, l);
        }
    }

    return bo.toString();
}

From source file:me.xingrz.prox.pac.AutoConfig.java

/**
 *  {@code url} ? PAC //from   w w  w.j a v a2  s. c  o  m
 *
 * @param url PAC ?
 * @return  {@code ProxAutoConfig} 
 * @throws IOException
 */
public static AutoConfig fromUrl(String url) throws IOException {
    HttpResponse response = new DefaultHttpClient().execute(new HttpGet(url));
    String config = EntityUtils.toString(response.getEntity());
    return new AutoConfig(config);
}

From source file:com.tweetlanes.android.urlservice.tweetmarker.TweetMarkerAPI.java

public static HttpResponse getRequest(String url, String debugName) {
    HttpClient client = new DefaultHttpClient();
    HttpGet request = new HttpGet();
    request.addHeader("X-Auth-Service-Provider", TwitterApi.TWITTER_VERIFY_CREDENTIALS_JSON);
    request.addHeader("X-Verify-Credentials-Authorization",
            TwitterManager.get().generateTwitterVerifyCredentialsAuthorizationHeader());
    HttpResponse response = null;/* w  ww . ja v a  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.cse.Controller.PermissionHolder.java

public static void revokePermissions(String... permisionString) {
    // String url="https://facebook.com/"
    DefaultHttpClient client = new DefaultHttpClient();
    HttpGet getReq = new HttpGet();
}

From source file:com.emobc.android.utils.HttpUtils.java

/**
 * Take a client address is https by default if
 * @param https//from  w w  w  .j a v a 2  s.  com
 * @return
 */
public static DefaultHttpClient getHttpClient(boolean https) {
    if (https) {
        HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;

        DefaultHttpClient client = new DefaultHttpClient();

        SchemeRegistry registry = new SchemeRegistry();
        SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
        socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
        registry.register(new Scheme("https", socketFactory, 443));
        SingleClientConnManager mgr = new SingleClientConnManager(client.getParams(), registry);
        DefaultHttpClient httpClient = new DefaultHttpClient(mgr, client.getParams());

        // Set verifier      
        HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
        return httpClient;
    }
    return new DefaultHttpClient();
}

From source file:org.carrot2.util.httpclient.HttpClientFactory.java

/**
 * @param timeout Timeout in milliseconds.
 * @return Returns a client with sockets configured to timeout after some sensible
 *         time./*from   ww  w.j  a  va 2 s  .c  om*/
 */
public static DefaultHttpClient getTimeoutingClient(int timeout) {
    final DefaultHttpClient httpClient = new DefaultHttpClient();

    configureProxy(httpClient);

    // Setup defaults.
    httpClient.setReuseStrategy(new NoConnectionReuseStrategy());

    httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, timeout);
    httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
    httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_LINGER, 0);

    return httpClient;
}