forked from gojue/ecapture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgolang_https.go
49 lines (44 loc) · 848 Bytes
/
golang_https.go
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
49
package main
/*
#include <stdio.h>
#include <stdlib.h>
void test() {
printf("hello CGO!\n");
}
*/
import "C"
import (
"crypto/tls"
"fmt"
"io"
"net/http"
"os"
"path/filepath"
)
func main() {
C.test()
b, e := GetHttp("https://baidu.com")
if e == nil {
fmt.Printf("response body: %s\n\n", b)
} else {
fmt.Printf("error :%v", e)
}
}
func GetHttp(url string) (body []byte, err error) {
f, err := os.OpenFile(filepath.Join(os.TempDir(), "ecapture_go_master_secret.log"), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
if err != nil {
panic(err)
}
defer f.Close()
c := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true, KeyLogWriter: f},
}}
resp, e := c.Get(url)
if e != nil {
return nil, e
}
defer resp.Body.Close()
body, err = io.ReadAll(resp.Body)
return body, err
}