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

时间:2018-06-06 08:55:24

标签: ssl go certificate skip

我在尝试向服务器发送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))

我在这里缺少什么?

0 个答案:

没有答案