linux java keystore_linux下java发送post请求以及安全证书问题

String url = "https://192.5.52.194:8868/nifi-api/access/token";

PostMethod postMethod= newPostMethod(url);

postMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");

NameValuePair[] data= {new NameValuePair("username", "test"), new NameValuePair("password", "123456")};

postMethod.setRequestBody(data);

HttpClient httpClient= newHttpClient();int response =httpClient.executeMethod(postMethod);

String result= postMethod.getResponseBodyAsString();

3.访问https时出现unable to find valid certification path to requested target问题时,是因为本地没有安装访问url的相应的证书。可以在能访问到该网址的机器上使用chrome浏览器访问该地址,并点击如下所示的地址前面的小锁标识。

bb84c41e04a9bce865fd544baa5e7ce2.png

然后在弹出的证书框上点击详细信息,然后点击复制文件

e0a2afa3b3e62916b4d98c5ac6cc6160.png

导出文件格式选择Base64编码,将证书导出到本地,例如命名为key.cer

05656d0b241e46110b5c42e0d5bc364a.png

将该文件上传到linux机器的/opt目录下。注意java的证书验证系统是独立于操作系统和浏览器的,因此要将证书加到jre证书库中,执行以下命令,执行过程中数据Y即可。

keytool -import -keystore "/usr/java/jdk1.8.0_60/jre/lib/security/cacerts" -storepass changeit -keypass changeit -alias twca -file /opt/key.cer

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值