最近项目中需要向外部服务发送https请求,但是外部服务测试环境提供的访问地址为https加ip、端口的访问方式,由于SSL签名认证问题(网上搜索大多说是因为https后面设计为跟域名绑定访问),无法访问,后来尝试网上各大神的解决方案,完美解决该问题。将代码保存下来,以备不时之需。
import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.message.BasicHeader; import org.apache.http.util.EntityUtils; /** * @param : * @author : mym * @version : V1.0 * @date : 2019/07/16 17:25 * @describe : 发送http请求 * @return : */ public class HttpClientUtil { /* * * @author : mym * @date Date : 2019/7/20 11:16 * @version : V1.0 * @describe : https发送json格式的请求 出参、入参都是json串 * @param : * @return : */ public static String doJsonPost(String url,String jsonstr,