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:biz.shadowservices.DegreesToolbox.HttpClientSingleton.java

public static HttpClient getInstance() {
    if (instance == null) {
        instance = new DefaultHttpClient();
        HttpParams httpParams = instance.getParams();
        HttpConnectionParams.setConnectionTimeout(httpParams, Values.TIMEOUT);
        HttpConnectionParams.setSoTimeout(httpParams, Values.TIMEOUT);
    }//from  w w  w .j ava2 s.co m
    return instance;
}

From source file:com.buddycloud.friendfinder.HttpUtils.java

public static JsonElement consumeJSON(String URL) throws Exception {
    HttpClient client = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(URL);
    HttpResponse httpResponse = client.execute(httpGet);

    JsonElement parse = new JsonParser()
            .parse(new JsonReader(new InputStreamReader(httpResponse.getEntity().getContent())));

    return parse;
}

From source file:Main.java

public static String postReqAsJsonAddParam(String uri, String requestJson, Map<String, String> param)
        throws ClientProtocolException, IOException {
    Log.i(TAG, "Send data to :" + uri + " ========== and the data str:" + requestJson);
    HttpPost post = new HttpPost(uri);
    List<NameValuePair> parameters = new ArrayList<NameValuePair>();
    for (Map.Entry<String, String> entry : param.entrySet()) {
        parameters.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
    }//from  ww w .ja va2  s.  co  m
    parameters.add(new BasicNameValuePair("attendanceClientJSON", requestJson));
    post.setEntity(new UrlEncodedFormEntity(parameters, "UTF-8"));
    HttpClient client = new DefaultHttpClient();
    HttpResponse response = client.execute(post);
    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        String retStr = EntityUtils.toString(response.getEntity());
        Log.i(TAG, "=================response str:" + retStr);
        return retStr;
    }

    return response.getStatusLine().getStatusCode() + "ERROR";
}

From source file:org.outburstframework.test.util.http.HTTPUtils.java

/**
 * Makes a HTTP Get request.//from  w w  w.  j av  a  2 s  .  com
 * 
 * @param url
  *          The URL fo the page you would like to return
 * @return The body of the HTTP request
 * @throws HTTPException
  *              The was a problem making the request
 * @throws InvalidResponseException
 *             The Response HTTP Status was not 200 OK
 */
public static String HTTPGet(String url) throws InvalidResponseException, HTTPException {
    HttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet(url);

    HttpResponse response;
    try {
        response = httpclient.execute(httpget);
    } catch (Exception e) {
        throw new HTTPException(e.getMessage(), e);
    }

    if (response.getStatusLine().toString().indexOf("200 OK") == -1) {
        throw new InvalidResponseException("Invalid status: " + response.getStatusLine());
    }

    try {
        return EntityUtils.toString(response.getEntity());
    } catch (Exception e) {
        throw new HTTPException(e.getMessage(), e);
    }
}

From source file:com.ilearnrw.reader.utils.HttpHelper.java

public static HttpResponse post(String url, String data) {
    DefaultHttpClient client = new DefaultHttpClient();
    HttpResponse response = null;/*from  w w w .j  a  v a  2  s. co m*/

    //HttpConnectionParams.setSoTimeout(client.getParams(), 25000);

    HttpPost post = new HttpPost(url);
    post.setHeader("Accept", "application/json");
    post.setHeader("Authorization", "Basic " + authString);
    post.setHeader("Content-Type", "application/json;charset=utf-8");

    try {
        post.setEntity(new StringEntity(data, HTTP.UTF_8));
        response = client.execute(post);
    } catch (ClientProtocolException e) {
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }

    return response;
}

From source file:com.plnyyanks.frcnotebook.datafeed.GET_Request.java

public static String getWebData(String url, boolean tbaheader) {

    InputStream is = null;//from   w w w.j a  va 2 s . co m
    String result = "";

    // HTTP
    try {
        HttpClient httpclient = new DefaultHttpClient(); // for port 80 requests!
        HttpGet httpget = new HttpGet(url);
        if (tbaheader)
            httpget.addHeader(Constants.TBA_HEADER, Constants.TBA_HEADER_TEXT);
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        is = entity.getContent();
    } catch (Exception e) {
        Log.e(Constants.LOG_TAG, e.toString());
        return null;
    }

    // Read response to string
    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(is, "utf-8"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        is.close();
        result = sb.toString();
    } catch (Exception e) {
        Log.e(Constants.LOG_TAG, e.toString());
        return null;
    }

    return result;

}

From source file:com.example.qrpoll.MyHttpURLConnection.java

/**
 * pobieranie zawartosci strony z serwera
 * @param url adres url strony z ktora chcemy sie polaczyc
 * @return zawartosc strony//w w w.  jav a  2s .c  o  m
 * @throws ClientProtocolException
 * @throws IOException
 * @throws Exception404 
 */
static public String get(String url) throws ClientProtocolException, IOException, Exception404 {
    HttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet(url);
    HttpResponse response = httpclient.execute(httpget);
    HttpEntity entity = response.getEntity();

    int code = response.getStatusLine().getStatusCode();
    if (code == 404)
        throw new Exception404();

    InputStream is = entity.getContent();
    BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
    StringBuilder sb = new StringBuilder();
    String line = null;
    while ((line = reader.readLine()) != null)
        sb.append(line + "\n");

    is.close();
    String resString = sb.toString();

    return resString;
}

From source file:com.grabtaxi.themoviedb.MyVolley.java

public static void init(Context context) {
    mHttpClient = new DefaultHttpClient();
    mRequestQueue = Volley.newRequestQueue(context, new HttpClientStack(mHttpClient));
    //        DiskLruBasedCache.ImageCacheParams cacheParams = new DiskLruBasedCache.ImageCacheParams(context, "thumbs");
    //        cacheParams.setMemCacheSizePercent(0.25f);
    mImageLoader = new SimpleImageLoader(context);
}

From source file:net.felixrabe.unleashthecouch.Utils.java

public static String getDocument(String couchDbDocUrl) {
    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(couchDbDocUrl);
    HttpResponse response = null;//from   w  w  w . j a v  a 2s. c  o  m
    try {
        response = httpClient.execute(httpGet);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            entity.writeTo(baos);
            return new String(baos.toByteArray(), "UTF-8");
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:cn.comgroup.tzmedia.server.util.mail.SendCloudMail.java

/**
* Send email using SMTP server./*w  w  w  .  j a v a 2 s .co m*/
*
* @param recipientEmail TO recipient
* @param title title of the message
* @param message message to be sent
* connected state or if the message is not a MimeMessage
*/
public static void send(String recipientEmail, String title, String message)
        throws UnsupportedEncodingException, IOException {
    String url = "http://sendcloud.sohu.com/webapi/mail.send.json";
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httpost = new HttpPost(url);

    List nvps = new ArrayList();
    // ??SendCloud?????????????????
    nvps.add(new BasicNameValuePair("api_user", "commobile_test_IxiZE1"));
    nvps.add(new BasicNameValuePair("api_key", "0tkHZ5vDdScYzRbn"));
    nvps.add(new BasicNameValuePair("from", "suport@tzzjmedia.net"));
    nvps.add(new BasicNameValuePair("to", recipientEmail));
    nvps.add(new BasicNameValuePair("subject", title));
    nvps.add(new BasicNameValuePair("html", message));

    httpost.setEntity(new UrlEncodedFormEntity(nvps, "UTF-8"));
    // 
    HttpResponse response = httpclient.execute(httpost);
    // ??
    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { // 
        // ?xml
        String result = EntityUtils.toString(response.getEntity());
        Logger.getLogger(SendCloudMail.class.getName()).log(Level.INFO, result);
    } else {
        System.err.println("error");
    }
}