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

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

}
相关推荐
Wy_编程1 天前
go中的协程Goroutine
开发语言·golang
会编程的土豆1 天前
Go 语言中的 `new` 关键字(创建指针)
java·算法·golang
喵了几个咪1 天前
Kratos 生态双定时器中间件:高精度 hptimer 与标准 cron 选型与实践
微服务·中间件·架构·golang·kratos
Achou.Wang2 天前
Concurrency patterns - Go 并发模式
开发语言·后端·golang
存在morning2 天前
【GO语言开发实践】三 GO 工程化快速上手
开发语言·后端·golang
Achou.Wang2 天前
Go语言并发编程中的死锁防范与破解之道
服务器·开发语言·golang
子安柠2 天前
深入理解 Go 反射:原理、实践与性能陷阱
开发语言·golang
福大大架构师每日一题2 天前
ollama v0.24.0 更新:Codex App 正式接入、内置浏览器、评审模式与 MLX 采样器重构,带来哪些变化?
重构·golang
会编程的土豆2 天前
Go ini 配置加载:`ini.MapTo` 详细解析
开发语言·数据库·golang
喵了几个咪2 天前
Kratos KCP 传输中间件:游戏开发低延迟网络通信实战指南
微服务·中间件·golang·游戏开发·kratos