本文整理汇总了Java中org.apache.http.util.EntityUtils.getContentCharSet方法的典型用法代码示例。如果您正苦于以下问题:Java EntityUtils.getContentCharSet方法的具体用法?Java EntityUtils.getContentCharSet怎么用?Java EntityUtils.getContentCharSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.util.EntityUtils
的用法示例。
在下文中一共展示了EntityUtils.getContentCharSet方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: postUrl
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
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");
httppost.setEntity(entity);
System.out.println(entity.toString());
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) {
e.printStackTrace();
} finally {
httpclient.getConnectionManager().shutdown();
}
return "";
}