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(); }
相关文章推荐
- iconv内容,convmv文件名,unix2dos,dos2unix文件格式转换,od/cut/wc/dd/diff/uniq/nice/du等命令,linux文件名乱码,文件名,文件内容,vim编码设置
- HttpClient设置编码类型
- 通过httpClient发送json格式数据请求
- httpclient发送http请求设置网络超时时间
- httpclient发送request请求时设置header和timeout
- HttpClientUtil发送json格式请求
- 利用cpdetector获取文件编码格式,同时得到网页内容。增加http/https通用方式
- 导出Excel,出现“服务器无法在发送HTTP标头之后设置内容类型”
- HttpClient发送请求后得到的响应内容出现部分乱码的问题
- asynchttpclient的post方法发送json格式参数和表单格式参数
- http协议之response案例三:【content-type】--服务器发送给浏览器的数据类型和数据编码格式
- Asp.Net服务器发送HTTP标头后无法设置内容类型的问题解决
- Windows 和 Linux下使用socket下载网页页面内容(可设置接收/发送超时)的代码(用socket解释http,不错)
- httpclient 编码设置
- iconv内容,convmv文件名,unix2dos,dos2unix文件格式转换,od/cut/wc/dd/diff/uniq/nice/du等命令,linux文件名乱码,文件名,文件内容,vim编码设置
- VC++使用CSocket发送HTTP Request时需要注意发送数据的编码格式
- HttpClient设置编码类型
- httpwebresponse 异步: request.BeginGetRequestStream 报错! 无法发送具有此谓词类型的内容正文。
- Web.Config中设置单个Aspx页面的编码格式
- 如何设置客户端每次发送请求的时候,保证都是新建一个http连接,而不是和上次的连接用同一个?