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

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

}
相关推荐
tachibana25 小时前
使用for range 的时候,它的地址会发生变化吗?
开发语言·后端·golang·go·语法
王中阳Go5 小时前
Go 后端转 AI:非科班怎么补?一张 3 列路线表(可保存)
开发语言·人工智能·后端·python·golang·大语言模型
for_ever_love__12 小时前
LangChain Agentic RAG:让 Agent 自己决定要不要检索、检索几次
人工智能·golang·langchain·rag·langgraph·agentic·自适应检索
谢亮_vipxieliang12 小时前
Go gRPC基础与实战
开发语言·后端·golang
徐小黑ACG13 小时前
Golang goroutine、通道、锁
开发语言·后端·golang
FfHUCisI1 天前
Go 性能分析工具 pprof:CPU、Heap 与 Goroutine 实战
数据库·golang
念何架构之路1 天前
go-grpc核心抽象接口
开发语言·后端·golang
小小龙学IT1 天前
etcd 深度解析:Go 分布式一致性 KV 存储与 Raft 共识实战
分布式·golang·etcd
谢亮_vipxieliang1 天前
Go Gin 中间件与参数验证:从入门到实战
中间件·golang·gin
microrain2 天前
同一个值,四个名字,四套口径:SagooIoT 属性上报链路的 Canonical 收敛
物联网·golang·开源·sagooiot