gpt4 book ai didi

http - Golang net/http2请求返回nil

转载 作者:行者123 更新时间:2023-12-01 21:12:20 26 4
gpt4 key购买 nike

package main

import (
gotls "crypto/tls"
"fmt"
"log"
"net"
"net/http"

tls "github.com/refraction-networking/utls"
"golang.org/x/net/http2"
)

func main() {
tr := &http2.Transport{
DialTLS: func(network, addr string, cfg *gotls.Config) (net.Conn, error) {
// fmt.Printf("DialTLS(%q, %q)\n", network, addr)
// conn, err := net.Dial(network, addr)
// if err != nil {
// return nil, err
// }
// uconn := utls.UClient(conn, &utls.Config{NextProtos: cfg.NextProtos}, utls.HelloChrome_83)

// return uconn, err
tcpConn, err := net.Dial(network, addr)
if err != nil {
return nil, err
}
config := tls.Config{ServerName: "ja3er.com"}
tlsConn := tls.UClient(tcpConn, &config, tls.HelloChrome_83)
err = tlsConn.Handshake()
if err != nil {
return nil, err
}
return tlsConn, nil
},
}

client := http.Client{
Transport: tr,
}
req, err := http.NewRequest("GET", "https://ja3er.com/json", nil)
if err != nil {
log.Fatal(err)
}
req.Header.Set("Connection", "keep-alive")
req.Header.Set("Cache-Control", "max-age=0")
req.Header.Set("Upgrade-Insecure-Requests", "1")
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36")
req.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9")
req.Header.Set("dnt", "1")
req.Header.Set("Sec-Fetch-Site", "none")
req.Header.Set("Sec-Fetch-Mode", "navigate")
req.Header.Set("Sec-Fetch-User", "?1")
req.Header.Set("Sec-Fetch-Dest", "document")
req.Header.Set("Accept-Language", "en-US,en;q=0.9")

resp, _ := client.Do(req)
fmt.Println(resp)
}
目前,我正在尝试通过Chrome_83的TLS客户端发送http2获取请求。我使用net / http模块使用了正常的http / 1.1版本,并尝试使用net / http2模块将其转换为http / 2,但是在发送此请求时,请求响应始终为nil。有人可以帮忙吗?
编辑:
我打印了请求错误,并收到以下消息: Get "https://ja3er.com/json": unexpected EOF

最佳答案

使用以下curl命令时,可以检查端点是否支持http 1.1或http 2。

curl -sI https://ja3er.com/json -o/dev/nul -w '%{http_version}\n'
结果是端点仅支持http 1.1

关于http - Golang net/http2请求返回nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64001484/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com