客户端访问服务器端的几种方式(Https)
按照 Glassfish4.1和Tomcat配置Https访问 设置好服务器端的https访问后,客户端可通过以下几种方式访问服务器端。
浏览器方式
用户在浏览器中输入相应url后,浏览器会弹出警告(由于使用了未认证的自定义证书),此时确认安全例外就可继续访问。终端方式
用户使用linux命令curl https://test.com
连接服务器,此时同样因为证书未被认证而会出现如下错误。curl: (60) Issuer certificate is invalid. More details here: http://curl.haxx.se/docs/sslcerts.html curl performs SSL certificate verification by default, using a "bundle" of Certificate Authority (CA) public keys (CA certs). If the default bundle file isn't adequate, you can specify an alternate file using the --cacert option. If this HTTPS server uses a certificate signed by a CA represented in the bundle, the certificate verification probably failed due to a problem with the certificate (it might be expired, or the name might not match the domain name in the URL). If you'd like to turn off curl's verification of the certificate, use the -k (or --insecure) option.
根据错误提示,有两种解决方案:
- 添加参数“-k”关闭证书检查
- 添加参数“–cacert cert_location”来指明证书位置,”cert_location“是从浏览器导出的该网站证书的位置。
java 程序
在java client程序中访问服务器时会抛出如下异常,解决方法见下一小节。javax.net.ssl.SSLHandshakeException: sun.