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

来源:互联网 发布:宿州煤电集团知乎 编辑:程序博客网 时间:2024/05/21 05:41
/** * 根据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();}

0 0
原创粉丝点击