golang TLS/SSL跳过证书验证失败

din*_*123 5 ssl certificate skip go

我试图在尝试向服务器发出 https 请求时跳过证书验证。client.Do() 失败并出现以下错误:

tls:无法解析来自服务器的证书:asn1:语法错误:PrintableString 包含无效字符

代码片段:

    var jsonStr = []byte(`{"grant_type":"client_credentials"}`)
    req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
    fmt.Println("req:>", req)

    //req.Header.Set("Content-Type", "application/json")
    req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
    req.SetBasicAuth("opennms", "test123~")

    tr := &http.Transport{
            TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
    }
    client := &http.Client{Transport: tr}

    //client := &http.Client{}
    resp, err := client.Do(req)
    fmt.Println("resp:>", resp)
    if err != nil {
            panic(err)
    }
    defer resp.Body.Close()

    body, _ := ioutil.ReadAll(resp.Body)
    fmt.Println("response Body:", string(body))
Run Code Online (Sandbox Code Playgroud)

我在这里缺少什么?