public String xmlHttpPost(String requestInfo, String urlAddress, boolean isProxy,
String proxyHost, int proxyPort, ContentType contentType) {
String responseInfo = null;
InputStream inputResStream = null;
try {
CloseableHttpClient httpClient = null;
if (isProxy) {
HttpHost proxy = new HttpHost(proxyHost, proxyPort);
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
httpClient = HttpClients.custom().setRoutePlanner(routePlanner).build();
}else{
httpClient = HttpClients.createDefault();
}
StringEntity stringEntity = new StringEntity(requestInfo, contentType);
HttpPost post = new HttpPost(urlAddress);
post.setEntity(stringEntity);
log.info("urlAddress: " + urlAddress.trim() + " proxyHost: " + proxyHost.trim() + " proxyPort: " + proxyPort);
CloseableHttpResponse response = httpClient.execute(post);
try {
HttpEntity entity = response.getEntity();
if (entity != null) {
inputResStream = entity.getContent();
try {
BufferedReader br = new BufferedReader(new InputStreamReader(inputResStream));
StringBuffer resBuffer = new StringBuffer();
String resTemp = "";
while ((resTemp = br.readLine()) != null) {
resBuffer.append(resTemp);
}
responseInfo = resBuffer.toString();
} finally {
inputResStream.close();
}
}
} finally {
response.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return responseInfo;
}
分享到:
相关推荐
Jakarta HttpComponents HTTPClient 。httpclient-4.3.5.jar
httpclient-4.3.5 Jakarta HttpComponents HTTPClient 。httpclient-4.3.5.jar
官方网站上最新的httpclient4.3.5
httpclient-4.3.5-sources.jar
try(CloseableHttpClient httpClient = HttpClients.createDefault()) { HttpPost httpPost = new HttpPost(url); StringEntity stringEntity = new StringEntity(params, Charset.forName("UTF-8")); ...
利用HttpClient发送HTTP请求 利用HttpClient发送HTTP请求
httpclient的用法,发送get请求和post请求,设置header
HttpCilent实现用到的包httpclient-4.3.5.jar和httpcore-4.3.2.jar
主要介绍了java 中HttpClient传输xml字符串实例详解的相关资料,需要的朋友可以参考下
NULL 博文链接:https://javasam.iteye.com/blog/2117845
其中包含项目post-demo定义接口;包含另一个项目httpclient-demo使用工具类发送post请求调用接口。详细内容查看博客 httpclient发送post请求
具体来说,它创建了一个HttpClient实例和一个HttpPost对象,设置了请求的URL、请求头和请求体,然后执行请求并获取响应。最后,它将响应内容输出到控制台。 这个代码的意义在于展示了如何使用Java中的HttpClient库...
不会的可以在评论区留言哈,这是我自己做项目用到的。所以绝对可用!同时共享出来给到大家
java HttpClient 发送GET请求和带有表单参数的POST请求教程例子
jsp 中HttpClient中的POST方法实例详解.docx
httpclient-4.3.5完美解决了 使用httpclient高版本时与Android系统包framework.jar有同类名冲突的问题。HttpClient可以用来提供高效的、最新的、功能丰富的支持 HTTP 协议的客户端编程工具包。httpclient 实现需要...
httpclient post方式发送json格式数据,需要的相关包。