-
大小: 14KB文件类型: .java金币: 1下载: 0 次发布日期: 2021-05-10
- 语言: Java
- 标签: HttpClient
资源简介
使用HttpClient4.5实现https请求忽略SSL证书验证工具类
代码片段和文件信息
package com.space.utils.http;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONobject;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.AuthSchemes;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* http请求工具类
*
* @author admin
*/
public class HttpUtils {
/**
* get
*
* @param host
* @param path
* @param headers
* @param queryMap
* @return
* @throws Exception
*/
public static HttpResponse doGet(String host String path
Map headers
Map queryMap)
throws Exception {
HttpClient httpClient = wrapClient(host path);
HttpGet request = new HttpGet(buildUrl(host path queryMap));
for (Map.Entry e : headers.entrySet()) {
request.addHeader(e.getKey() e.getValue());
}
request.setConfig(setTimeOutConfig(request.getConfig()));
return httpClient.execute(request);
}
/**
* post form
*
* @param host
* @param path
* @param headers
* @param queryMap
* @param bodyMap
* @return
* @throws Exception
*/
public static HttpResponse doPost(String host String path
Ma
- 上一篇:java相关项目实战.txt
- 下一篇:java学习视频网盘分享
相关资源
- 基于HttpClient 4.3的可访问自签名HTTPS站
- httpclient-4.5.5 完整架包
- HttpClient发送http请求需要的jar包
- httpClient jar包.rar
- httpclient-4.5所需jar包
- commons-httpclient-3.0.jar
- httpclient-4.5 jar
- org.apache.commons.httpclient. jar
- android httpclient asynctask demo
- httpcore-4.2.4.jar 和 httpclient-4.2.5.jar
- java 访问 wcf 使用的HttpClient
- httpcore-4.3.2和httpclient-4.3.3.jar
- HttpClient官方最新jar包。
- org.apache.commons.httpclient. jar 程序文件
- httpclient-4.5.1.jar
- HttpClientUtil工具类,调用第三方接口
- httpclient过时用的jar包
- HttpClient 4.3.1必要jar包
- Android通过POST和GET向服务器发送数据
- httpclient-4.2.5.jar
- Httpclient所需jar包
- 使用HttpClient图片
- HttpClient所需jar包(全) httpClient.4.1
- commons-httpclient相关jar包
- http和WebService 调用接口Java代码demo
- Android httpclient获取到JSON数据并展示到
评论
共有 条评论