解决httpClient调用https的peer not authenticated终极解决方法_By christiecat

该博客详细介绍了在Java中使用Apache HttpClient进行HTTPS请求时遇到的'peer not authenticated'错误的解决方案。通过加载CA证书到KeyStore,创建自定义SSLSocketFactory并注册到HttpClient,成功地解决了安全认证问题,实现了安全的HTTPS通信。
摘要由CSDN通过智能技术生成

import java.io.FileInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.security.KeyStore;
import java.security.cert.Certificate;
import java.security.cert.CertificateFactory;

import javax.net.ssl.SSLSocketFactory;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.eclipse.jdt.internal.compiler.ast.Invocation;
import org.springframework.beans.factory.annotation.Autowired;

import net.sf.json.JSONObject;

public class HttpsUtils {
@Autowired
Invocation inv;
/**

  • Request Headers
    */
    final static String CONTENTTYPE = “application/json;charset=utf-8”;
    pu
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值