作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试通过uTLS库使用Hello Chrome指纹发送请求,但是在浏览了文档之后,我试图弄清楚如何在发送请求时利用uTLS连接。
我已经在下面的代码的两个部分,但不确定如何将它们放在一起,或者我是否正在正确的方式。
package main
import (
"fmt"
"io/ioutil"
"net"
"net/http"
"net/http/cookiejar"
tls "github.com/refraction-networking/utls"
)
func main() {
tcpConn, err := net.Dial("tcp", "151.101.65.69:443")
if err != nil {
fmt.Printf("net.Dial() failed: %+v\n", err)
return
}
config := tls.Config{ServerName: "www.stackoverflow.com"}
tlsConn := tls.UClient(tcpConn, &config, tls.HelloChrome_Auto)
defer tlsConn.Close()
err = tlsConn.Handshake()
if err != nil {
fmt.Printf("uTlsConn.Handshake() error: %+v", err)
} else {
fmt.Println("Handshake met")
}
cookieJar, _ := cookiejar.New(nil)
client := &http.Client{
Jar: cookieJar,
Transport: &http.Transport{},
}
req, err := http.NewRequest("GET", "https://ja3er.com/json", nil)
req.Header.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36")
resp, err := client.Do(req)
if err != nil {
fmt.Println(err)
} else {
fmt.Println(resp.StatusCode)
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
}
最佳答案
只需将您的代码移到Transport.DialTLSContext:
DialTLSContext指定用于创建的可选拨号功能
非代理HTTPS请求的TLS连接。
[...]
返回的net.Conn假定已经是
经过TLS握手。
client := &http.Client{
Jar: cookieJar,
Transport: &http.Transport{
DialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
// Note that hardcoding the address is not necessary here. Only
// do that if you want to ignore the DNS lookup that already
// happened behind the scenes.
tcpConn, err := (&net.Dialer{}).DialContext(ctx, network, addr)
if err != nil {
return nil, err
}
config := tls.Config{ServerName: "www.stackoverflow.com"}
tlsConn := tls.UClient(tcpConn, &config, tls.HelloChrome_Auto)
err = tlsConn.Handshake()
if err != nil {
return nil, fmt.Errorf("uTlsConn.Handshake() error: %w", err)
}
return tlsConn, nil
},
},
}
关于http - 发送请求时如何使用uTLS连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63054147/
我已经使用 brew install vowpal-wabbit 在我的 Mac 上安装了 Wowpal-wabbit。 vw 命令工作正常。不过,我想使用 \utl\ folder of the l
我是一名优秀的程序员,十分优秀!