1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
| package main
import (
"crypto/tls"
"fmt"
"io"
"log"
"net/http"
"os"
"strings"
"time"
)
func getClient() (*http.Client, error) {
// 读取环境配置
sslkeyfile := os.Getenv("SSLKEYLOGFILE")
if sslkeyfile == "" {
return nil, errors.New("no SSLKEYLOGFILE environment variable")
}
keyLogWriter, err := os.OpenFile(sslkeyfile, os.O_APPEND|os.O_RDWR, 0600)
if err != nil {
panic(err)
}
return &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
// 本篇文章重点,设置Key日志
KeyLogWriter: keyLogWriter,
},
}}, nil
}
func main() {
client, _ := getClient()
// 发送 GET 请求
resp, err := client.Get("https://reatang.com")
if err != nil {
fmt.Println("Failed to send request:", err)
return
}
defer resp.Body.Close()
// 打印响应状态码
fmt.Println("Response status:", resp.Status)
}
|