资源简介
java http工具,包括get、post、json格式请求,使用httpclient
代码片段和文件信息
package com.xgdmsr.common.utils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
/**
* http工具类
*/
public class HttpUtil {
private static final Log logger = LogFactory.getLog(HttpUtil.class);
private static String ENCOCE_UTF_8 = “UTF-8“;
private static CloseableHttpClient client = null;
private HttpUtil() {
}
private static CloseableHttpClient getClientInstance() {
if (client == null) {
synchronized (HttpUtil.class) {
if (client == null) {
// 设置每个路由的最大并发连接数为20以提高性能,默认为2
client = HttpClientBuilder.create().setMaxConnPerRoute(20)
.build();
}
}
}
return client;
}
/**
* @param url
* @return
* @throws ClientProtocolException
* @throws IOException
*/
public static String httpGet(String url) throws ClientProtocolException IOException {
// 创建httpget
HttpGet httpGet = new HttpGet(url);
HttpResponse response = getClientInstance().execute(httpGet);
HttpEntity entity = response.getEntity();
return EntityUtils.toString(entity);
}
public static HttpEntity httpGetForEntity(String url) throws Exception {
HttpGet httpGet = new HttpGet(url);
HttpResponse response = getClientInstance().execute(httpGet);
return response.getEntity();
}
/**
* post请求
*
* @param url
* @param params
* @return
* @throws ClientProtocolException
* @throws IOException
*/
public static String httpPost(String url Map params) throws
相关资源
- httpcore-4.4.4.jar-4.4.4.jar
- 购物系统设计与实现外文资料
- OkHttpClientUtil封装类
- adnroid开发框架rxjava+dagger2+retrofit2okh
- android替换Glide通讯组件为Okhttp并监控
- OKHttp网络请求jar包
- java使用HttpClient通过url文件到本地
- java httpclient 模拟登录
-
Android MediaPla
yer与Http Proxy结合之优化 -
Android MediaPla
yer与Http Proxy结合之基础 - Android_HttpClient_jar包
- AsyncHttpClient所需的jar包
- httpclient-android-4.3.5.1.jar
- android jni使用curl进行http请求和文件
- C#通过SOAP使用HttpWebRequest调用带有身份
- okhttp3(包含http-3.9.0.jar和okio1.13.0.ja
- java通过HTTP调用接口Get请求和Post请求
- tomcat httpHeaderSecurity.jar
- httpclient-4.3.6.jar架包
- httpclientjar包
- com.sun.net.httpserver.jar
- java:静态web服务器实现http
- httpclient需要的jar包,合订版httclient
- java写的目前最完美的http代理程序
- httpmime-4.1.1.jar
- httpservletrequest的jar包
- android httpclient
- Java实现Web服务器和客户端
- Android 使用OkHttp3报错处理
- java 调用okHttp3进行代码测试SpringBoot项
评论
共有 条评论