Golang - http请求InsecureSkipVerify 字段为 true 来忽略忽略 SSL验证

在Golang中,可以通过设置 tls.Config 的 InsecureSkipVerify 字段为 true 来忽略 SSL 验证。

下面是一个简单的示例代码:

Go 复制代码
package main

import (
	"crypto/tls"
	"fmt"
	"net/http"
)

func main() {
	// 创建一个自定义的 Transport
	tr := &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
	}

	// 创建一个使用自定义 Transport 的 HTTP 客户端
	client := &http.Client{Transport: tr}

	// 发送 GET 请求
	resp, err := client.Get("https://example.com")
	if err != nil {
		fmt.Println("Error:", err)
		return
	}
	defer resp.Body.Close()

	// 读取响应内容
	// ...

}
相关推荐
码途行者5 小时前
每天10分钟学Go:第23课 协程(goroutine)
开发语言·后端·golang
利威尔xu8 小时前
2026-11-25-Go-panic-recover面试
面试·golang
码途行者8 小时前
每天10分钟学Go:第24课 通道-协程之间的传送带
开发语言·后端·golang
codeejun3 天前
每日一Go·MySQL-22、幻读、不可重复读、脏读实战演示
开发语言·mysql·golang
码途行者4 天前
每天10分钟学Go:第17课 接口interface-只规定“能做什么“,不管它是什么
开发语言·后端·golang
利威尔xu4 天前
2026-11-24-Go限流器实战
后端·golang
码途行者4 天前
每天10分钟学Go:第21课 错误
开发语言·后端·golang
码途行者5 天前
每天10分钟学Go:第22课 自定义错误
开发语言·后端·golang
码途行者5 天前
每天10分钟学Go:第20课 泛型
c++·算法·golang
codeejun5 天前
每日一Go·MySQL-20、SQL 性能调优实战总结
sql·mysql·golang