Example usage for org.apache.http.protocol HTTP UTF_8

List of usage examples for org.apache.http.protocol HTTP UTF_8

Introduction

In this page you can find the example usage for org.apache.http.protocol HTTP UTF_8.

Prototype

String UTF_8

To view the source code for org.apache.http.protocol HTTP UTF_8.

Click Source Link

Usage

From source file:com.android.idtt.http.client.ResponseStream.java

public ResponseStream(HttpResponse baseResponse, String url, long expiry) throws IOException {
    this(baseResponse, HTTP.UTF_8, url, expiry);
}

From source file:org.cvasilak.jboss.mobile.admin.net.ssl.CustomHTTPClient.java

public static synchronized AbstractHttpClient getHttpClient() {
    try {/*from   ww  w .java 2 s . c o  m*/
        if (client == null) {
            KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
            trustStore.load(null, null);

            SSLSocketFactory sf = new EasySSLSocketFactory(trustStore);
            sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

            HttpParams params = new BasicHttpParams();
            HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
            HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);

            SchemeRegistry registry = new SchemeRegistry();
            registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
            registry.register(new Scheme("https", sf, 443));

            ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);

            client = new DefaultHttpClient(ccm, params);
        }
    } catch (Exception e) {
        Log.d(TAG, "unable to create http client", e);
    }

    return client;
}

From source file:yuki312.android.metrobucket.content.net.GsonAndUtf8ResponseRequest.java

@Override
protected String onInterceptParseNetworkResponse(NetworkResponse response) throws UnsupportedEncodingException {
    return new String(response.data, HTTP.UTF_8);
}

From source file:cn.com.infohold.p2papp.common.gate.OtherUtils.java

public static String getFileNameFromHttpResponse(final HttpResponse response) {
    if (response == null)
        return null;
    String result = null;/*  w  w  w .  j  a va  2 s  .c  om*/
    Header header = response.getFirstHeader("Content-Disposition");
    if (header != null) {
        for (HeaderElement element : header.getElements()) {
            NameValuePair fileNamePair = element.getParameterByName("filename");
            if (fileNamePair != null) {
                result = fileNamePair.getValue();
                // try to get correct encoding str
                result = CharsetUtils.toCharset(result, HTTP.UTF_8, result.length());
                break;
            }
        }
    }
    return result;
}

From source file:com.abombrecords.amt_unlocker.AMT_Unlocker.java

public static boolean UnlockDoor(String Username, String Password, String DoorPIN) throws Exception {
    boolean bSuccess = false;

    //Log.d(LogTag, "Login");   
    DefaultHttpClient httpclient = new DefaultHttpClient();

    HttpPost httpost = new HttpPost("http://acemonstertoys.org/node?destination=node");

    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    nvps.add(new BasicNameValuePair("op", "Log in"));
    nvps.add(new BasicNameValuePair("name", Username));
    nvps.add(new BasicNameValuePair("pass", Password));
    nvps.add(new BasicNameValuePair("openid.return_to",
            "http://acemonstertoys.org/openid/authenticate?destination=node"));
    nvps.add(new BasicNameValuePair("form_id", "user_login_block"));
    nvps.add(new BasicNameValuePair("form_build_id", "form-4d6478bc67a79eda5e36c01499ba4c88"));

    httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

    HttpResponse response = httpclient.execute(httpost);
    HttpEntity entity = response.getEntity();

    //Log.d(LogTag, "Login form get: " + response.getStatusLine());
    if (entity != null) {
        entity.consumeContent();/*from  ww  w.  j a  va  2 s  . c o  m*/
    }

    //Log.d(LogTag, "Post Login cookies:");
    // look for drupal_uid and fail out if it isn't there
    List<Cookie> cookies = httpclient.getCookieStore().getCookies();
    if (cookies.isEmpty()) {
        //Log.d(LogTag, "None");
    } else {
        for (int i = 0; i < cookies.size(); i++) {
            //Log.d(LogTag, "- " + cookies.get(i).toString());

            if (cookies.get(i).getName().equals("drupal_uid")) {
                bSuccess = true;
            }
        }
    }

    if (bSuccess) {
        HttpPost httpost2 = new HttpPost("http://acemonstertoys.org/membership");

        List<NameValuePair> nvps2 = new ArrayList<NameValuePair>();
        nvps2.add(new BasicNameValuePair("doorcode", DoorPIN));
        nvps2.add(new BasicNameValuePair("forceit", "Open Door"));

        httpost2.setEntity(new UrlEncodedFormEntity(nvps2, HTTP.UTF_8));

        response = httpclient.execute(httpost2);
        entity = response.getEntity();

        //Log.d(LogTag, "Unlock form get: " + response.getStatusLine());
        if (entity != null) {
            entity.consumeContent();
        }
    }

    httpclient.getConnectionManager().shutdown();

    return bSuccess;
}

From source file:net.bither.api.BitherErrorApi.java

@Override
public HttpEntity getHttpEntity() throws Exception {
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    if (!Utils.isEmpty(this.mErrorMsg)) {
        params.add(new BasicNameValuePair(ERROR_MSG, this.mErrorMsg.trim()));
    }/*from   www  .j a va2s. c  o m*/
    return new UrlEncodedFormEntity(params, HTTP.UTF_8);
}

From source file:cn.isif.util_plus.http.ResponseStream.java

public ResponseStream(HttpResponse baseResponse, String requestUrl, long expiry) throws IOException {
    this(baseResponse, HTTP.UTF_8, requestUrl, expiry);
}

From source file:azureml_besapp.AzureML_BESApp.java

/**
 * Call REST API to submit job to Azure ML for batch predictions
 * @return response from the REST API//from ww w.  j  a v a  2 s  .co m
 */
public static String besHttpPost() {

    HttpPost post;
    HttpClient client;
    StringEntity entity;

    try {
        // create HttpPost and HttpClient object
        post = new HttpPost(apiurl);
        client = HttpClientBuilder.create().build();

        // setup output message by copying JSON body into 
        // apache StringEntity object along with content type
        entity = new StringEntity(jsonBody, HTTP.UTF_8);
        entity.setContentEncoding(HTTP.UTF_8);
        entity.setContentType("text/json");

        // add HTTP headers
        post.setHeader("Accept", "text/json");
        post.setHeader("Accept-Charset", "UTF-8");

        // set Authorization header based on the API key
        post.setHeader("Authorization", ("Bearer " + apikey));
        post.setEntity(entity);

        // Call REST API and retrieve response content
        HttpResponse authResponse = client.execute(post);

        jobId = EntityUtils.toString(authResponse.getEntity()).replaceAll("\"", "");

        return jobId;

    } catch (Exception e) {

        return e.toString();
    }

}

From source file:com.redwoodsystems.android.apps.utils.HttpUtil.java

public static HttpClient getNewHttpClient() {
    try {//w  ww.j av  a2  s.  co  m
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);

        SSLSocketFactory sf = new MySSLSocketFactory(trustStore);
        sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);

        ConnManagerParams.setTimeout(params, HTTP_TIMEOUT);

        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        registry.register(new Scheme("https", sf, 443));

        ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);

        return new DefaultHttpClient(ccm, params);
    } catch (Exception e) {
        return new DefaultHttpClient();
    }
}

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

/**
 * <p>Executes the given HTTP request using the given HTTP client,
 * and returns the received entity as string.
 * Returns <code>null</code> if the query was performed (i.e. the server
 * was reachable) but resulted in a failure,
 * e.g. 404 error.</p>/* ww w  .  j av a2s .  c o m*/
 * 
 * @param client HTTP client
 * @param request HTTP request (e.g. GET or POST)
 * @return response as String
 * @throws IOException
 */
public static String getResponseEntityAsString(HttpClient client, HttpUriRequest request) throws IOException {
    try {
        HttpResponse response = client.execute(request);
        HttpEntity entity = response.getEntity();

        if (entity == null) {
            return null;
        }
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            return null;
        }
        if (entity.getContentEncoding() == null) {
            return EntityUtils.toString(entity, HTTP.UTF_8);
        }
        return EntityUtils.toString(entity);
    } finally {
        client.getConnectionManager().shutdown();
    }
}