我尝试从 HTTP 切换到 HTTPS:
func handler(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.Write([]byte("This is an example server.\n"))
}
func main() {
http.HandleFunc("/", handler)
log.Printf("About to listen on 8080. Go to https://127.0.0.1:8080/")
err := http.ListenAndServeTLS(":8080", "cert.pem", "key.pem", nil)
if err != nil {
log.Fatal(err)
}
}
我收到以下错误:
crypto/tls: failed to parse key PEM data
我的应用程序现在以 HTTP 模式运行,我希望它以 HTTPS 模式运行。
谁能建议如何使它在 HTTPS 中工作?