java.security.InvalidAlgorithmParameterException: parameter object not a ECParameterSpec
今天在开发中碰到一个问题,在调用外部接口时,报了这样的异常。
代码如下:
/**
* 获取token
*
* @param projectKey 项目秘钥
* @return token
*/
private String getToken(String projectKey) {
String token = null;
// 生成请求参数
Map<String, Object> map = new HashMap<>();
map.put("secret", projectKey);
String json = JSON.toJSONString(map);
// 发送请求
String result = HttpUtil.post(getDataUrl + DockingConstant.getTokenUrl, json);
// 解析请求结果
JSONObject jsonObject = JSONObject.parseObject(result);
String flag = jsonObject.getString("success");
if ("true".equals(flag)) {
String data = jsonObject.getString("data");
JSONObject tokenJson = JSONObject.parseObject(data);
token = tokenJson.getString("token");
}
return token;
}
异常是在使用hutool的HttpUtil工具类发送请求时报出的,但是在main方法是直接用HttpUtil工具类发送没有问题,当我尝试在接口中使用字符串常量代替变量发送请求时,还是报了这个异常。降低了hutool的版本也没用。请求百度,但是与之相关的问题很少,就算有也不是这个问题。奇怪的是,代码在Eclipse中运行也没有问题,就是idea配置问题了,再看了下异常:
java.security.InvalidAlgorithmParameterException: parameter object not a ECParameterSpec
at org.bouncycastle.jce.provider.JDKKeyPairGenerator$EC.initialize(Unknown Source)
at sun.security.ssl.ECDHCrypt.<init>(ECDHCrypt.java:77)
at sun.security.ssl.ClientHandshaker.serverKeyExchange(ClientHandshaker.java:783)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:302)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1037)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:965)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1064)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1395)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1379)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1340)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1315)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:264)
at cn.hutool.http.HttpConnection.getOutputStream(HttpConnection.java:449)
at cn.hutool.http.HttpRequest.sendFormUrlEncoded(HttpRequest.java:1177)
at cn.hutool.http.HttpRequest.send(HttpRequest.java:1146)
at cn.hutool.http.HttpRequest.execute(HttpRequest.java:959)
at cn.hutool.http.HttpRequest.execute(HttpRequest.java:930)
at cn.hutool.http.HttpUtil.post(HttpUtil.java:228)
at cn.hutool.http.HttpUtil.post(HttpUtil.java:209)
知道是网络连接的问题。请求的url没错,也能ping通,可能就是代理问题了。
我找了springboot服务启动时的配置,把jmx代理的√给去掉了,问题就解决了,离谱。
开发小白,各位大佬有其他解决办法或者知道原理的,求求大佬跟我交流哦。