Created
December 8, 2023 03:04
-
-
Save diyism/d7ff55cc0f1b7a49ca1674dfe7ea2606 to your computer and use it in GitHub Desktop.
directly call libcronet.so from cronet-go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ref: https://github.com/sleeyax/cronet-binaries/issues/1 | |
package main | |
import ( | |
"net/http" | |
"os" | |
"github.com/sagernet/cronet-go" | |
) | |
func main() { | |
client := &http.Client{ | |
Transport: &cronet.RoundTripper{}, | |
} | |
// 创建新的 HTTP 请求 | |
req, err := http.NewRequest("GET", "https://www.google.com/ncr", nil) | |
if err != nil { | |
panic(err) | |
} | |
// 设置请求头 | |
req.Header.Set("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1556.0") | |
// 发送 HTTP 请求 | |
response, err := client.Do(req) | |
if err != nil { | |
} | |
response.Write(os.Stderr) | |
response.Body.Close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment