https中证书起到身份验证和加密传输的作用.
后来证实是证书问题,访问站点证书有问题,无法确认所以无法建立连接并得到响应.
golang如何不确认证书
以post方式为例,get类同
package main
import (
"crypto/tls"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"strings"
)
func main() {
// InsecureSkipVerify 跳过证书确认
client := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
}
login := "/rest_v2/"
login = addr + login
// form args
vals := url.Values{}
vals.Add("method","login")
vals.Add("name","admin")
vals.Add("password","password")
request, _ := http.NewRequest("POST", login, strings.NewReader(vals.Encode()))
// set headers
request.Header.Add("Content-Type", "application/x-www-form-urlencoded")
request.Header.Set("Connection", "Keep-Alive")
fmt.Println(request)
resp, _ := client.Do(request)
defer resp.Body.Close()
fmt.Println(resp)
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
postman 如何不确认证书
setting-general-SSL certificate verification 设置为OFF
python 如何不确认证书
import requests
# verify=False跳过证书确认
以get方式为例
url = "https://www.baidu.com"
response = requests.get (url, verify=False)
print(response.status_code)
有疑问加站长微信联系(非本文作者)