java - 使用 OkHttpClient 连接到 API 导致 TLS 错误
问题描述
我在尝试使用 OkHttpClient 连接到 APi 服务器时遇到错误,对此进行了充分的研究并尝试了任何可能有帮助的选项
我正在使用 Eclipse,我的错误是“连接被对等方关闭”,我无法解决它,所以我下载了 OkHttp 的 jar 文件,然后我发现了错误:
Unable to find acceptable protocols. isFallback=false, modes=[ConnectionSpec(cipherSuites=[TLS_DHE_RSA_WITH_AES_256_CBC_SHA], tlsVersions=[TLS_1_2], supportsTlsExtensions=true)], supported protocols=[SSLv3, TLSv1]
……
String r = "";
Response response;
try {
String url = "https://api.honeywell.com/oauth2/token";
RequestBody requestBody = new
MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML").build();
Request request = new Request.Builder().url(url).post(requestBody).build();
OkHttpClient client = new OkHttpClient();
ConnectionSpec spec = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS).tlsVersions(TlsVersion.TLS_1_2)
.cipherSuites(CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA).build();
client = new OkHttpClient.Builder().connectionSpecs(Collections.singletonList(spec)).build();
try {
response = client.newCall(request).execute();
r = response.body().toString();
} catch (IOException e) {
r = "1111 " + e.getMessage();
}
} catch (Exception e) {
r = "222 " + e.getMessage();
}
return r;
谁能帮助我如何设置 ConnectioSpecs?我认为这是我的问题,我放在那里的东西我放的东西有误。
感谢您调查我的问题,因为我迷路了。
解决方案
推荐阅读
- javascript - 如何防止 MathJax 渲染的元素窃取右键单击事件?
- r - 数据框r和grepl中的两个条件
- c# - 在 SignalR 中将用户添加到 Hub 组
- python - 使用 Dialogflow Python API 在 Dialogflow 代理内创建知识库的问题
- javascript - jQuery - 不允许加载本地资源
- javascript - ReactJs:如何在 RegionDropdown 中选择默认值
- javascript - 在远程方法 beforeRemote 钩子上的 Loopback 中发送回响应
- angular - 按日期持续时间的角度过滤器数组
- hive - 如何在蜂巢中以驼峰形式保留列名
- java - Bean 名称“...”的 BindingResult 和普通目标对象都不能用作请求属性