打开输入流时发生 SSL 错误
我想我想了解 SSL 是如何工作的,我有基于 grails 的应用程序作为应用程序过程的一部分,我们必须打开与第 3 方应用程序的“https”连接。 但遇到以下异常
"sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"
虽然与 URL 的连接工作正常,但当我尝试打开输入流以读取数据时会发生错误。问题是,如果存在证书问题,我在打开连接时应该不会遇到问题吗? 附上代码片段
try{
URL url= new URL("https://.../..")
def c = url.openConnection()
println("connection successful with Merchant")
def result = c.inputStream.text?.trim() // results in error
println(result)
}
catch (Exception exp){
println("error !!!")
println(exp.getMessage())
}
I guess I am trying to understand how SSL works, I have grails based application as part of application process we have to open "https" connection to a 3rd party application.
But running into following exception
"sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"
Though connection to the URL works fine but error happens when I try to open input Stream for reading data. Question is if there is certificate problem shouldn't I have problem while opening connection ?
code snippet is attached
try{
URL url= new URL("https://.../..")
def c = url.openConnection()
println("connection successful with Merchant")
def result = c.inputStream.text?.trim() // results in error
println(result)
}
catch (Exception exp){
println("error !!!")
println(exp.getMessage())
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于刚开始使用 SSL 和证书管理的人来说,这是一个非常常见的问题。我在我的博客上题为“导入非众所周知的证书”的文章中用非常详细的示例和命令回答了这个问题 AllInGeek.com。
This is a very common problem for people starting out with SSL and certificate management. I answer this question with very detailed examples and commands in an article titled, "Importing non-well known certificates" on my blog AllInGeek.com.
这仅意味着您要连接的 Web 服务器或 URL 没有来自授权 CA 的有效证书。
您可以通过另一个 ssl 站点验证这一点
或按照此处的步骤操作:
http://www.java-samples.com/showtutorial .php?tutorialid=210
通过导入服务器证书来解决该问题。
This simply means that the web server or the URL you are connecting to does not have a valid certificate from an authorized CA.
You could verify this with another ssl site
or follow the steps here:
http://www.java-samples.com/showtutorial.php?tutorialid=210
to work around the issue by importing the servers certificate.