2020年最后一天啦,2021年我来啦,哈哈哈
正文如下:
Tomcat 版本:9.0.37
报错截图:
根据tomcat 9官网说明
说明从Tomcat 9开始,通过证书别名进行区分。
并且需要将connector的协议调整为:org.apache.coyote.http11.Http11NioProtocol(Tomcat 9Https默认配置)
原文地址:https://tomcat.apache.org/tomcat-9.0-doc/ssl-howto.html#Edit_the_Tomcat_Configuration_File
阿里也提到Tomcat 9要将证书的别名设置为tomcat
原文地址:https://help.aliyun.com/document_detail/98576.html?spm=a2c4g.11186623.2.11.1a15d39eRQvi3w#concept-omf-lxn-yfb
Keytool参数说明:
C:\Users\Administrator>keytool
密钥和证书管理工具
命令:
-certreq 生成证书请求
-changealias 更改条目的别名
-delete 删除条目
-exportcert 导出证书
-genkeypair 生成密钥对
-genseckey 生成密钥
-gencert 根据证书请求生成证书
-importcert 导入证书或证书链
-importpass 导入口令
-importkeystore 从其他密钥库导入一个或所有条目
-keypasswd 更改条目的密钥口令
-list 列出密钥库中的条目
-printcert 打印证书内容
-printcertreq 打印证书请求的内容
-printcrl 打印 CRL 文件的内容
-storepasswd 更改密钥库的存储口令
查看当前证书别名的命令:
keytool -list -v -keystore android.keystore
其中:android.keystore为证书文件
修改证书别名的命令:
keytool -changealias -keystore android.keystore -alias my_name -destalias androiddebugkey
其中:android.keystore为证书文件
my_name为当前证书别名
androiddebugkey为修改后证书别名
按照上述方式修改完后,依然报错:
需要调整代码:
protected String doInBackground(String... strings) {
final String url = strings[0];
//得到httpclient对象
DefaultHttpClient client = new DefaultHttpClient();
//封装get请求
HttpGet hg=new HttpGet(url);
//获取返回的response
try {
//修改org.apache.http的主机名验证解决问题
SSLSocketFactory.getSocketFactory().setHostnameVerifier(new AllowAllHostnameVerifier());
HttpResponse response = client.execute(hg);
//获取状态码
int statusCode = response.getStatusLine().getStatusCode();
if(statusCode==200){
//entiry 里面封装的数据;
HttpEntity entity = response.getEntity();
//这个result就是json字符串,剩下的就是解析工作了;
String s = EntityUtils.toString(entity);
return s;
}