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.worthed.googleplus.HttpUtils.java

/**
 * Send post request.//from  ww  w  . j  a  v a 2 s.c  o m
 * @param url 
 * @param params
 * @return It's a error if result start with "Error:".
 */
public String doPost(String url, List<NameValuePair> params) {
    HttpClient httpClient = getHttpClient();
    /* HTTPPost */
    HttpPost httpRequest = new HttpPost(url);
    String strResult = ERROR_PREFIX;

    try {
        /* ? */
        httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
        /* ??? */
        HttpResponse httpResponse = httpClient.execute(httpRequest);
        /* ??200 ok */
        if (httpResponse.getStatusLine().getStatusCode() == 200) {
            /* ? */
            strResult = EntityUtils.toString(httpResponse.getEntity());
        } else {
            strResult += httpResponse.getStatusLine().toString();
        }
    } catch (ClientProtocolException e) {
        strResult += e.getMessage().toString();
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        strResult += e.getMessage().toString();
        e.printStackTrace();
        return null;
    } catch (Exception e) {
        strResult += e.getMessage().toString();
        e.printStackTrace();
        return null;
    }
    Log.w(TAG, strResult);
    return strResult;
}

From source file:cache.reverseproxy.CachedResponseParser.java

public static GenericHttpResponse getResponse(String fileName, boolean isSoap) throws IOException {
    String fileDir = ProxyConfig.getOutputDir(isSoap);

    File file = new File(fileDir + "/" + fileName);
    if (!file.exists() || !file.canRead() || file.isDirectory()) {
        return null;
    }/*from w  w w. j  ava  2s .co  m*/

    GenericHttpResponse response = new GenericHttpResponse();

    BufferedReader br = new BufferedReader(new FileReader(file));
    StringBuffer fileContents = new StringBuffer();
    String line = br.readLine();
    boolean isHeadRetrieved = false;
    boolean isFirst = true;
    while (line != null) {
        if (!isFirst && !isHeadRetrieved) {
            fileContents.append("\r\n");
            if (line != null) {
                String ucaseLine = line.toUpperCase();
                if (ucaseLine.indexOf("CONTENT-TYPE") > -1 && ucaseLine.indexOf(HTTP.UTF_8) > -1) {
                    response.encoding = HTTP.UTF_8;
                }
            }
        }
        if (!isFirst || !"".equals(line)) {
            fileContents.append(line);
        }

        isFirst = false;
        line = br.readLine();
        if ("".equals(line) && !isHeadRetrieved) {
            isHeadRetrieved = true;
            response.headers = fileContents.toString();
            fileContents = new StringBuffer();
            isFirst = true;
        }
    }

    if (isHeadRetrieved) {
        response.entity = fileContents.toString();
    } else {
        response.headers = fileContents.toString();
    }

    br.close();
    /*System.out.println("FromFile:BEGIN");
    System.out.println(response.headers);
    System.out.println(response.entity);
    System.out.println("FromFile:END");*/
    return response;
}

From source file:com.sepgil.ral.UpdateNodeTask.java

@Override
public HttpRequestBase getHttpRequest(String url) {
    HttpPost post = new HttpPost(url);

    try {// ww  w.j  a va  2 s.  co m
        StringEntity enity = new StringEntity(mNode.getJSON(), HTTP.UTF_8);
        post.setEntity(enity);
    } catch (JSONException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return post;
}

From source file:org.addhen.smssync.tests.util.DataFormatUtilTest.java

/**
 * Test make xml string from List of pair values
 *///  ww w . j  a  v a  2  s  . co  m
@SmallTest
public void testMakeXMLString() throws IOException {
    String actual = DataFormatUtil.makeXMLString(pairs, "zz", HTTP.UTF_8);
    String expected = "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><zz><a>b</a><c>d</c></zz>";
    assertNotNullOrEqual("XML cannot be null and must be formatted correctly", expected, actual);
}

From source file:com.strato.hidrive.api.connection.httpgateway.request.PostRequest.java

@SuppressWarnings("unchecked")
protected HttpRequestBase createHttpRequest(String requestUri, HttpRequestParamsVisitor<?> visitor)
        throws UnsupportedEncodingException {
    HttpPost httpPost = new HttpPost(requestUri);
    //There used StringEntity and some string manipulations instead of UrlEncodedFormEntity due to problem in url encoding ("+" instead "%20")
    //details: http://stackoverflow.com/questions/7915029/how-to-encode-space-as-20-in-urlencodedformentity-while-executing-apache-httppo
    String entityValue = URLEncodedUtils.format((List<NameValuePair>) visitor.getHttpRequestParams(),
            HTTP.UTF_8);
    entityValue = entityValue.replaceAll("\\+", "%20");
    StringEntity entity = new StringEntity(entityValue, HTTP.UTF_8);
    entity.setContentType(URLEncodedUtils.CONTENT_TYPE);
    httpPost.setEntity(entity);/*from   w  ww .j a v  a 2 s. c o  m*/
    //original code:
    //httpPost.setEntity(new UrlEncodedFormEntity((List<? extends NameValuePair>) visitor.getHttpRequestParams(), HTTP.UTF_8));
    return httpPost;
}

From source file:com.uc.dca.util.HttpHandler.java

public String post(String uri, List<NameValuePair> nvps) throws IOException {
    HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(uri);
    httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
    Log.d(TAG, "executing post " + httpPost.getURI());
    // Create a response handler
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    String responseBody = httpClient.execute(httpPost, responseHandler);
    //        Log.d(TAG, responseBody);
    return responseBody;

}

From source file:com.fanfou.app.opensource.http.SimpleResponse.java

public final String getContent() throws IOException {
    if (this.entity != null) {
        return EntityUtils.toString(this.entity, HTTP.UTF_8);
    }//  w w w. j av a  2s.co m
    return null;
}

From source file:com.nimpres.android.web.APIContact.java

/**
 * Performs a post request to the specified api with the specified parameters and returns the result
 * //  w w w . j  a  va 2s  .  c o  m
 * @param apiAddress
 * @param postParams
 * @return the result in an HttpEntity object
 */
public static BufferedHttpEntity apiPostRequest(String apiAddress, List<NameValuePair> postParams) {
    BufferedHttpEntity resEntity = null;
    try {
        HttpClient client = new DefaultHttpClient();
        // Set address for API call
        HttpPost post = new HttpPost(getAPIAddress(apiAddress));
        // Add post parameters to request
        UrlEncodedFormEntity ent = new UrlEncodedFormEntity(postParams, HTTP.UTF_8);
        post.setEntity(ent);
        // Send post and store result
        Log.d("APIContact", "Contacting API - api-method:" + apiAddress + ", api-query: " + postParams);
        HttpResponse responsePOST = client.execute(post);
        resEntity = new BufferedHttpEntity(responsePOST.getEntity());
        String result = EntityUtils.toString(resEntity);
        Log.d("APIContact", "post result: " + result);
        if (resEntity != null) {
            return resEntity;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:de.escidoc.core.test.aa.UserPreferenceTestBase.java

/**
 * Test creating a user preference.//from  w w  w  .j av  a2s  .  c o  m
 *
 * @param id       The id of the UserAccount.
 * @return The xml representation of the created preference.
 * @throws Exception If anything fails.
 */
protected String createPreference(final String id, final String xml) throws Exception {
    Object result = client.createPreference(id, xml);
    String xmlResult = null;
    if (result instanceof HttpResponse) {
        HttpResponse method = (HttpResponse) result;
        xmlResult = EntityUtils.toString(method.getEntity(), HTTP.UTF_8);
        assertHttpStatusOfMethod("", method);

    } else if (result instanceof String) {
        xmlResult = (String) result;
    }
    return xmlResult;
}

From source file:org.nuxeo.android.simpleclient.menus.AboutActivity.java

public void onFulfillDisplayObjects() {
    webView.loadDataWithBaseURL("file:///android_asset/", content, "text/html", HTTP.UTF_8, null);
}