Skip to content

Instantly share code, notes, and snippets.

@diyism
Created December 8, 2023 03:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diyism/d7ff55cc0f1b7a49ca1674dfe7ea2606 to your computer and use it in GitHub Desktop.
Save diyism/d7ff55cc0f1b7a49ca1674dfe7ea2606 to your computer and use it in GitHub Desktop.
directly call libcronet.so from cronet-go
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