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

I'm trying to skip certificate verification while trying to do a https request to a server. The client.Do() fails with the following error:

tls: failed to parse certificate from server: asn1: syntax error: PrintableString contains invalid character

Code Snippet:

    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))

What am I missing here?

dp926460
dp926460 可能什么都没有。纯服务器错误。略读crypto/tls以获取有关如何根本不读取ASN.1的选项可能会有所帮助。
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐