Java Code Examples for org.apache.http.util.EntityUtils.getContentCharSet()

The following are Jave code examples for showing how to use getContentCharSet() of the org.apache.http.util.EntityUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: weixinpay   File:   View Source Code Vote up 6 votes
public static String postUrl(String url, String body) {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(url);
    httppost.getParams().setParameter(HttpProtocolParams.HTTP_CONTENT_CHARSET, "UTF-8");

    //请求超时 ,连接超时
    httpclient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT);
    httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, SO_TIMEOUT);

    try {
        StringEntity entity = new StringEntity(body, "UTF-8");


        HttpResponse response = httpclient.execute(httppost);

        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            String charsetName = EntityUtils.getContentCharSet(response.getEntity());
            //System.out.println(charsetName + "<<<<<<<<<<<<<<<<<");

            String rs = EntityUtils.toString(response.getEntity());
            //System.out.println( ">>>>>>" + rs);

            return rs;
        } else {
            //System.out.println("Eorr occus");
    } catch (Exception e) {

    } finally {

    return "";