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

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

}
相关推荐
小小龙学IT11 小时前
Go 泛型深度解析:从设计哲学到工程实践
服务器·数据库·golang
张忠琳13 小时前
【Go 1.26.4】(Part 2) Go 1.26.4 超深度分析 — Runtime GMP 调度器 (proc.go + runtime2.go)
开发语言·golang
踏着七彩祥云的小丑17 小时前
Go学习第5天:变量作用域 + 数组 + 指针
开发语言·学习·golang·go
Lewiis18 小时前
白话桶排序
数据结构·算法·golang·排序算法
咖啡星人k18 小时前
MonkeyCode 后端架构全解析:Go微服务如何支撑万级并发AI任务
微服务·架构·golang·monkeycode
张忠琳18 小时前
【Go 1.26.4】Golang Interface 接口深度解析
开发语言·golang
伊灵eLing19 小时前
GoLang 语言高级(1)
开发语言·后端·golang
张忠琳19 小时前
【Go 1.26.4】(Part 8) Go 1.26.4 超深度分析 — context + reflect + errors
开发语言·golang
张忠琳19 小时前
【Go 1.26.4】(Part 3) Go 1.26.4 超深度分析 — Runtime GC 垃圾收集 (mgc*.go + mbitmap.go)
开发语言·golang
leo_yu_yty1 天前
Go语言分布式计算(并发Debug)
开发语言·笔记·后端·golang