NutzCN Logo
问答 用Nutz的Http.get调用企业微信的接口报:java.lang.IllegalArgumentException: TLSv1.1
发布于 1679天前 作者 Mrxiky 1795 次浏览 复制 上一个帖子 下一个帖子
标签:

求大佬赐教,就是简单的get请求,https。用nutz封装的org.nutz.http工具,调用报以下错误。
浏览器直接输入url也能请求成功的。

2020-05-18 22:20:40:153 [org.nutz.mvc.impl.processor.FailProcessor]-[WARN]: Error@/apply/gettemplatedetail/{某个参数} :
org.nutz.http.HttpException: url=https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={打码}&corpsecret={打码}
at org.nutz.http.sender.GetSender.send(GetSender.java:22)
at org.nutz.http.Http.get(Http.java:171)
at org.nutz.http.Http.get(Http.java:167)
at pfm.wechat.config.ApplyConfig.getAccessTokenFromUrl(ApplyConfig.java:70)
at pfm.wechat.config.ApplyConfig.getAccessToken(ApplyConfig.java:53)
at pfm.wechat.service.ApplyService.gettemplatedetail(ApplyService.java:18)
at pfm.wechat.module.ApplyModule.gettemplatedetail(ApplyModule.java:18)
at pfm.wechat.module.ApplyModule$FM$gettemplatedetail$f5b03e2892fe27aabe6c1923a5b7e59b.invoke(ApplyModule.java)
at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:31)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:30)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at pfm.passport.processor.PassportProcessor.process(PassportProcessor.java:105)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: TLSv1.1
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1488)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(HttpURLConnection.java:3018)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:489)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338)
at org.nutz.http.Sender.getResponseHeader(Sender.java:144)
at org.nutz.http.sender.GetSender.send(GetSender.java:19)
... 52 more
Caused by: java.lang.IllegalArgumentException: TLSv1.1
at sun.security.ssl.ProtocolVersion.valueOf(ProtocolVersion.java:187)
at sun.security.ssl.ProtocolList.convert(ProtocolList.java:84)
at sun.security.ssl.ProtocolList.(ProtocolList.java:52)
at sun.security.ssl.SSLSocketImpl.setEnabledProtocols(SSLSocketImpl.java:2504)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:463)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1546)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
... 55 more

4 回复

你需要新版jdk

来自炫酷的 NutzCN

jdk是1.8的,要升级到多少?这是自己jdk的问题吗

jdk8u112以上

来自炫酷的 NutzCN

找到原因了,晕死了,defaultSetup里藏着这段代码。https.protocols设置为"TLSv1.2, TLSv1.1, TLSv1",逗号后面多了个空格,看了源码发现split后TLSv1.1解析成“ TLSv1.1”,多个空格匹配不对。直接抛错误参数。。。吐血

@Override
public void init(final NutConfig config) {
String cdn = config.getInitParameter("cdn");
config.setAttribute("cdn", cdn);

    System.setProperty("https.protocols", "TLSv1.2, TLSv1.1, TLSv1");  
    // 设置默认文档编码方式 UTF-8
    System.setProperty("file.encoding", "UTF-8");
    // 设置默认文档分割格式 /
    System.setProperty("file.separator", "/");

    // 初始化
    Ioc ioc = config.getIoc();
}
添加回复
请先登陆
回到顶部