3 回答

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超4個(gè)贊
從評(píng)論中的討論來(lái)看,問(wèn)題似乎與https
握手有關(guān)。
一個(gè)簡(jiǎn)單的解決方案是使用以下 URL 查詢(xún)服務(wù):
curl -H "Content-type:application/json" -X GET 'https://localhost:50051/testapp/v1/order' -v -k
使用-k
,您將忽略HTTPS
驗(yàn)證。
注意:我已將 URL 從更改http
為https
.

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超10個(gè)贊
從容器內(nèi)部,您需要偵聽(tīng)所有接口,而不是 localhost 或環(huán)回接口。網(wǎng)絡(luò)是在 docker 中命名的,因此您不僅可以獲得一個(gè)新的私有 ip,還可以獲得容器內(nèi)部一個(gè)無(wú)法從外部訪問(wèn)的單獨(dú)環(huán)回接口。為此,請(qǐng)更改:
http.ListenAndServe("localhost:50051", headersOk)
到:
http.ListenAndServe(":50051", headersOk)

TA貢獻(xiàn)1779條經(jīng)驗(yàn) 獲得超6個(gè)贊
上提供的代碼main.go不會(huì)啟動(dòng) TLS,因此請(qǐng)停止使用 curl 來(lái)卷曲https,它將無(wú)法正常工作。卷曲http會(huì)起作用
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向您確認(rèn)您請(qǐng)求的端口上不存在 TLS
很多評(píng)論確認(rèn) usinghttps不相關(guān),再次在您的代碼上未激活 TLS
curl -H "Content-type:application/json" -X GET 'http://localhost:50051/testapp/v1/order'作品。再次確認(rèn) 不使用 TLS
結(jié)論:
https當(dāng)您的代碼上未激活 TLS 時(shí),不要嘗試 curl
- 3 回答
- 0 關(guān)注
- 180 瀏覽
添加回答
舉報(bào)