我有一個使用 HTTP/2 工作的基本客戶端和服務器實現。我想測試服務器是否也適用于 HTTP/1。有什么方法可以將協議從 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}服務器代碼: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貢獻1878條經驗 獲得超4個贊
我找到了一個簡單的解決方案。
客戶端的變化
Transport: &http2.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
},
經過
Transport: &http.Transport{
TLSNextProto: make(map[string]func(authority string, c *tls.Conn) http.RoundTripper),
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
},
- 1 回答
- 0 關注
- 209 瀏覽
添加回答
舉報
0/150
提交
取消