linux无法访问https接口,Linux环境中https请求失败

今天用Request创建一个post API请求, 然后在本地测试是OK的, 但布署到正式环境就报了下面的异常:

Exception in thread "main" org.nutz.http.HttpException: url=https://xxxxxxxxxxxx

at org.nutz.http.sender.PostSender.send(PostSender.java:38)

at com.touyun.crontabjob.hdmilk.util.SyncDataFromPlatform.getData(SyncDataFromPlatform.java:90)

at com.touyun.crontabjob.hdmilk.util.SyncDataFromPlatform.loadBabyInfo(SyncDataFromPlatform.java:51)

at com.touyun.crontabjob.hdmilk.MainSetup.main(MainSetup.java:28)

Caused by: javax.net.ssl.SSLKeyException: RSA premaster secret error

at sun.security.ssl.RSAClientKeyExchange.(RSAClientKeyExchange.java:86)

at sun.security.ssl.ClientHandshaker.serverHelloDone(ClientHandshaker.java:880)

at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:344)

at sun.security.ssl.Handshaker.processLoop(Handshaker.java:936)

at sun.security.ssl.Handshaker.process_record(Handshaker.java:871)

at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1043)

at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1343)

at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1371)

at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1355)

at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563)

at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)

at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1281)

at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1256)

at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)

at org.nutz.http.sender.PostSender.send(PostSender.java:29)

... 3 more

Caused by: java.security.NoSuchAlgorithmException: SunTls12RsaPremasterSecret KeyGenerator not available

at javax.crypto.KeyGenerator.(KeyGenerator.java:158)

at javax.crypto.KeyGenerator.getInstance(KeyGenerator.java:207)

at sun.security.ssl.JsseJce.getKeyGenerator(JsseJce.java:272)

at sun.security.ssl.RSAClientKeyExchange.(RSAClientKeyExchange.java:77)

... 17 more

初步认定是验证证书的问题, 为此增加了下面的代码, 关闭检验:

Http.disableJvmHttpsCheck();

但最终的结果还是报同样的错误, 求指教. 源代码如下:

String getData(String url, boolean isNew, String lastMD) {

Map headers = new HashMap();

headers.put("AuthInfo", "sao.so");

headers.put("Content-Type", "application/json");

String result = "";

String body = "{\"isNew\":" + isNew + ",\"lastMD\":\"" + lastMD + "\"}";

try {

Http.disableJvmHttpsCheck();

Request req = Request.create(url, METHOD.POST);

req.setEnc("UTF-8");

req.setData(body);

req.setHeader(Header.create(headers));

Response resp = Sender.create(req, 5 * 1000).send();

if (resp.isOK()) {

String content = resp.getContent();

return content;

}

return result;

} catch (HttpException e) {

throw Lang.wrapThrow(e, "An exception was happend when get data from paltform.");

}

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值