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:de.koczewski.maxapi.WebClientDevWrapper.java

public static DefaultHttpClient createClient() {
    return wrapClient(new DefaultHttpClient());
}

From source file:com.sinfonier.util.JSonUtils.java

public static void sendPostDucksBoard(Map<String, Object> json, String url, String apiKey) {
    HttpClient httpClient = new DefaultHttpClient();
    Gson gson = new GsonBuilder().create();
    String payload = gson.toJson(json);

    HttpPost post = new HttpPost(url);
    post.setEntity(new ByteArrayEntity(payload.getBytes(Charset.forName("UTF-8"))));
    post.setHeader("Content-type", "application/json");

    try {/*from   w ww. j av  a  2  s  . c  o m*/
        post.setHeader(new BasicScheme().authenticate(new UsernamePasswordCredentials(apiKey, "x"), post));
    } catch (AuthenticationException e) {
        e.printStackTrace();
    }

    try {
        HttpResponse response = httpClient.execute(post);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void sendData(final String targetUrl, final String idField, final String tempField,
        final String feelingField, final String symptomsField, final String id, final String temp,
        final String feeling, final ArrayList<String> symptoms) {
    new Thread(new Runnable() {
        public void run() {
            // Create a new HttpClient and Post Header
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(targetUrl);

            try {
                // Add your data
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                nameValuePairs.add(new BasicNameValuePair(idField, id));
                nameValuePairs.add(new BasicNameValuePair(tempField, temp));
                nameValuePairs.add(new BasicNameValuePair(feelingField, feeling));
                for (int i = 0; i < symptoms.size(); i++) {
                    nameValuePairs.add(new BasicNameValuePair(symptomsField, symptoms.get(i)));
                }/*from  ww  w. j  ava 2 s.  c  o m*/
                // Must put this extra pageHistory field here, otherwise Forms will reject the
                // symptoms.
                nameValuePairs.add(new BasicNameValuePair("pageHistory", "0,1"));

                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                // Execute HTTP Post Request
                HttpResponse response = httpclient.execute(httppost);
            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }).start();
}

From source file:com.nuance.expertassistant.HTTPConnection.java

public static JSONObject sendGet(String getURL) throws Exception {

    String url = getURL;/*from  www. java 2s .  c  o  m*/

    HttpClient client = new DefaultHttpClient();
    HttpGet request = new HttpGet(url);

    // add request header
    request.addHeader("User-Agent", USER_AGENT);

    System.out.println(" The URL is :" + url);

    HttpResponse response = client.execute(request);

    System.out.println("\nSending 'GET' request to URL : " + url);
    System.out.println("Response Code : " + response.getStatusLine().getStatusCode());

    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

    StringBuilder builder = new StringBuilder();
    for (String line = null; (line = rd.readLine()) != null;) {
        builder.append(line).append("\n");
    }

    System.out.print("JSON TEXT : " + builder.toString());

    String jsonText = builder.toString();

    if (jsonText.startsWith("[")) {
        jsonText = jsonText.substring(1, jsonText.length());
    }

    if (jsonText.endsWith("]")) {
        jsonText = jsonText.substring(0, jsonText.length() - 1);
    }

    JSONObject object = new JSONObject(jsonText);

    return object;

}

From source file:tw.org.tsos.bsrs.MyVolley.java

static void init(Context context) {
    mClient = new DefaultHttpClient();
    mRequestQueue = Volley.newRequestQueue(context/*,new HttpClientStack(mClient)*/);

    int memClass = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
    // Use 1/8th of the available memory for this memory cache.
    int cacheSize = 1024 * 1024 * memClass / 8;
    mImageLoader = new ImageLoader(mRequestQueue, new BitmapLruCache(cacheSize));
}

From source file:ee.ioc.phon.netspeechapi.Utils.java

/**
 * @see #getResponseEntityAsString(HttpClient client, HttpUriRequest request)
 *///from   ww w .  j  ava 2  s.c  o  m
public static String getResponseEntityAsString(HttpUriRequest request) throws IOException {
    return getResponseEntityAsString(new DefaultHttpClient(), request);
}

From source file:org.gbif.ipt.model.factory.ExtensionFactoryTest.java

public static ExtensionFactory getFactory() throws ParserConfigurationException, SAXException {
    IPTModule mod = new IPTModule();
    SAXParserFactory sax = mod.provideNsAwareSaxParserFactory();
    DefaultHttpClient client = new DefaultHttpClient();
    ExtensionFactory factory = new ExtensionFactory(new ThesaurusHandlingRule(new MockVocabulariesManager()),
            sax, client);//  w w w . j  av a  2 s .  co  m
    return factory;
}

From source file:com.ibm.xsp.xflow.activiti.util.HttpClientUtil.java

public static String post(String url, Cookie[] cookies, String content) {
    String body = null;/*  w  w w.jav a  2 s  . com*/
    try {
        StringBuffer buffer = new StringBuffer();
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost postRequest = new HttpPost(url);

        StringEntity input = new StringEntity(content);
        input.setContentType("application/json");
        postRequest.setEntity(input);

        httpClient.setCookieStore(new BasicCookieStore());
        String hostName = new URL(url).getHost();
        String domain = hostName.substring(hostName.indexOf("."));
        for (int i = 0; i < cookies.length; i++) {
            if (logger.isLoggable(Level.FINEST)) {
                logger.finest("Cookie:" + cookies[i].getName() + ":" + cookies[i].getValue() + ":"
                        + cookies[i].getDomain() + ":" + cookies[i].getPath());
            }
            BasicClientCookie cookie = new BasicClientCookie(cookies[i].getName(), cookies[i].getValue());
            cookie.setVersion(0);
            cookie.setDomain(domain);
            cookie.setPath("/");

            httpClient.getCookieStore().addCookie(cookie);
        }
        HttpResponse response = httpClient.execute(postRequest);
        BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));

        String output;
        if (logger.isLoggable(Level.FINEST)) {
            logger.finest("Output from Server .... \n");
        }
        while ((output = br.readLine()) != null) {
            if (logger.isLoggable(Level.FINEST)) {
                logger.finest(output);
            }
            buffer.append(output);
        }

        httpClient.getConnectionManager().shutdown();

        body = buffer.toString();

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

    return body;
}

From source file:com.flowzr.budget.holo.rates.ExchangeRateProviderFactory.java

private static HttpClientWrapper createDefaultWrapper() {
    return new HttpClientWrapper(new DefaultHttpClient());
}

From source file:org.transitime.avl.amigocloud.AmigoRest.java

/********************** Member Functions **************************/

private static DefaultHttpClient getThreadSafeClient() {
    DefaultHttpClient client = new DefaultHttpClient();
    ClientConnectionManager mgr = client.getConnectionManager();
    HttpParams params = client.getParams();
    client = new DefaultHttpClient(new ThreadSafeClientConnManager(params, mgr.getSchemeRegistry()), params);
    return client;
}