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

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

}
相关推荐
sunly_4 小时前
Go 切片详解
开发语言·oracle·golang
利威尔xu7 小时前
Go interface 底层:空接口装任何东西,类型断言漏写 ok 直接 panic 拖垮服务
开发语言·golang·interface·类型断言·itab
Zenova EdgeOS7 小时前
Go Redis 实战:工业边缘场景下的 go-redis
数据库·redis·golang·边缘计算·工业网关
利威尔xu11 小时前
Go defer 十连问:LIFO 顺序答错参数求值时机,3 处资源泄漏拖垮服务
开发语言·golang·defer·recover·panic
NendoZen1 天前
Bubble Tea V2构建Go TUI应用教程
开发语言·golang·xcode
pan_junbiao1 天前
Go 语言变量的声明与初始化
开发语言·javascript·golang
pan_junbiao2 天前
Go 语言基本数据类型
java·前端·golang
Yang96112 天前
OTDR的动态范围和盲区怎么读?以鼎讯GO-38PRO拆解参数
后端·golang·otdr·光时域
codeejun2 天前
每日一Go·MySQL-24、死锁排查与解决方案
开发语言·mysql·golang
利威尔xu2 天前
Go context取消传播3层:信号传不到第3层goroutine,泄漏拖垮
后端·golang