我有一個(gè)使用 HTTP/2 工作的基本客戶端和服務(wù)器實(shí)現(xiàn)。我想測(cè)試服務(wù)器是否也適用于 HTTP/1。有什么方法可以將協(xié)議從 HTTP/2 更改為 HTTP/1.x?客戶端代碼:func main() { host = "https://127.0.0.1:8080" client = http.Client{ // InsecureTLSDial is temporary and will likely be // replaced by a different API later. Transport: &http2.Transport{ TLSClientConfig: &tls.Config{ InsecureSkipVerify: true, }, }, } // further functionality}服務(wù)器代碼:func main() { var srv http.Server srv.Addr = ":8080" // Set Routes routes() // Start server srv.ListenAndServeTLS("certs/localhost.cert", "certs/localhost.key")}
1 回答

UYOU
TA貢獻(xiàn)1878條經(jīng)驗(yàn) 獲得超4個(gè)贊
我找到了一個(gè)簡(jiǎn)單的解決方案。
客戶端的變化
Transport: &http2.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
},
經(jīng)過(guò)
Transport: &http.Transport{
TLSNextProto: make(map[string]func(authority string, c *tls.Conn) http.RoundTripper),
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
},
- 1 回答
- 0 關(guān)注
- 217 瀏覽
添加回答
舉報(bào)
0/150
提交
取消