您的位置:首页 > 理论基础 > 计算机网络

HttpClient设置发送内容的编码格式

2016-12-06 12:42 309 查看
/**
* 根据url获取输入流(POST),https,利用HttpClient
*
* @param url
* @param content
* @param accessToken
* @return
* @throws IOException
* @throws NoSuchProviderException
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
*/
public static InputStream getHttpsInputStreamByHttpClient(String url, String content)
throws IOException, NoSuchAlgorithmException, NoSuchProviderException, KeyManagementException {
String action = url;
CloseableHttpClient httpclient = HttpClients.custom().build();
HttpPost httpPost=new HttpPost(url);
StringEntity stringEntity=new StringEntity(content.toString(),"utf-8"); //这里设置发送内容的编码格式
httpPost.setEntity(stringEntity);
CloseableHttpResponse response = httpclient.execute(httpPost);
HttpEntity entity = response.getEntity();
return entity.getContent();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐