3 回答

TA貢獻1796條經驗 獲得超4個贊
從評論中的討論來看,問題似乎與https
握手有關。
一個簡單的解決方案是使用以下 URL 查詢服務:
curl -H "Content-type:application/json" -X GET 'https://localhost:50051/testapp/v1/order' -v -k
使用-k
,您將忽略HTTPS
驗證。
注意:我已將 URL 從更改http
為https
.

TA貢獻1802條經驗 獲得超10個贊
從容器內部,您需要偵聽所有接口,而不是 localhost 或環回接口。網絡是在 docker 中命名的,因此您不僅可以獲得一個新的私有 ip,還可以獲得容器內部一個無法從外部訪問的單獨環回接口。為此,請更改:
http.ListenAndServe("localhost:50051", headersOk)
到:
http.ListenAndServe(":50051", headersOk)

TA貢獻1779條經驗 獲得超6個贊
上提供的代碼main.go不會啟動 TLS,因此請停止使用 curl 來卷曲https,它將無法正常工作。卷曲http會起作用
package main
import (
"io"
"net/http"
"github.com/gorilla/handlers"
)
func main() {
http.HandleFunc("/testapp/v1/order", testHandler)
headersOk := handlers.AllowedHeaders([]string{""})
http.ListenAndServe(":50051", headersOk)
}
func testHandler(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "Heyyy!")
}
該命令openssl s_client https://localhost:50051/testapp/v1/order -connect localhost:50051向您確認您請求的端口上不存在 TLS
很多評論確認 usinghttps不相關,再次在您的代碼上未激活 TLS
curl -H "Content-type:application/json" -X GET 'http://localhost:50051/testapp/v1/order'作品。再次確認 不使用 TLS
結論:
https當您的代碼上未激活 TLS 時,不要嘗試 curl
- 3 回答
- 0 關注
- 175 瀏覽
添加回答
舉報