我想寫一個基本的http服務器示例。我可以捲曲localhost:8080
,但無法通過客戶端腳本與http.Get("127.0.0.1:8080")
聯繫服務器。我究竟做錯了什麼?Golang http.Get()
server.go:
import "fmt"
import "net/http"
func join(w http.ResponseWriter, req *http.Request) {
fmt.Println("Someone joined")
}
func main() {
fmt.Println("Listening on port 8080...")
http.HandleFunc("/join", join)
http.ListenAndServe(":8080", nil)
}
client.go:
import "net/http"
http.Get("127.0.0.1:8080/join")
「我[...]不能聯繫服務器」是不是一個有用的描述交流你所面臨的問題。順便說一句:捕獲和處理來自http.Get的錯誤將在這裏提供信息。 – Volker