SDK 相关问题
如何获取 SDK 调用样例?
如何导入 SDK ?
JDK1.7 使用 SDK 调用上传文件接口报 javax.net.ssl.SSLException-Received fatal alert: protocol_version?
JDK1.7 默认使用 TLSv1.0,需要强制设置成 TLSv1.2,官方使用的 HTTP 客户端是 okhttp,需要自行修改官网 SDK 源码。
在 com.tencentcloudapi.common.http.HttpConnection 类中修改构造函数如下:
public HttpConnection(Integer connTimeout, Integer readTimeout, Integer writeTimeout) {this.client = new OkHttpClient();SSLContext sslContext = null; //这边指定tls版本try {sslContext = SSLContext.getInstance("TLSv1.2");sslContext.init(null, null,null);} catch (Exception e) {e.printStackTrace();throw new RuntimeException(e.getMessage());}SSLSocketFactory factory = sslContext.getSocketFactory();this.client.setSslSocketFactory(factory);this.client.setConnectTimeout(connTimeout, TimeUnit.SECONDS);this.client.setReadTimeout(readTimeout, TimeUnit.SECONDS);this.client.setWriteTimeout(writeTimeout, TimeUnit.SECONDS);}