drtldt55533
2018-05-15 10:04
浏览 98
已采纳

tls.Dial返回“地址中的冒号太多”

I am trying to loop through an array of addresses, and check their tls cert status. I pieced together a program from various examples that do other things.

My first step in processing is

conn, err := tls.Dial("tcp", url, nil)

where 'url' is passed in from the array (I do import crypto/tls). Before I go on to pulling the cert, I check for errors:

if err != nil { 
    log.Printf("Unable to get %q - %s
", url, err)
    return
}

Here is a snippet of the array (with only test addresses for now):

var urls = []string{
    "https://google.com:443",
    "https://expired.badssl.com:443",
    "[https://wrong.host.badssl.com]:443",
    "[https://self-signed.badssl.com]:443"
}

The first 2 return too many colons in address I found a suggestion to fix that using the brackets. The next 2 addresses, with the brackets, return no such host

Where is my error?

图片转代码服务由CSDN问答提供 功能建议

我正在尝试遍历地址数组,并检查其tls证书状态。 我从各种示例中组装了一个程序来做其他事情。

处理的第一步是

  conn,err:= tls  .Dial(“ tcp”,url,nil)
   
 
 

其中'url'是从数组传入的(我确实导入了 crypto / tls )。 在继续获取证书之前,我检查是否存在错误:

  if err!= nil {
 log.Printf(“无法获取%q-%s \  n”,网址,错误)
 return 
} 
   
 
 

这是数组的摘要(目前只有测试地址):

  var urls = [] string {
“ https://google.com:443",
” https://expired.badssl.com:443",
“  [https://wrong.host.badssl.com]:443“,
” [https://self-signed.badssl.com]:443“ 
} 
   \  n 
 

前2个返回地址中的冒号太多 我发现了一个使用括号来解决该问题的建议。 接下来的2个地址(带有方括号)返回没有这样的主机

我的错误在哪里?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douxi3432 2018-05-15 10:09
    已采纳

    It should be domain name, IPv4 or IPv6 address with port only, not URL.

    conn, err := tls.Dial("tcp", "mail.google.com:443", &tls.Config{
        RootCAs: roots,
    })
    
    点赞 打赏 评论

相关推荐 更多相似问题