|
28精币
论坛里下的一个源码中附带的go源码
想用易实现
代码如下
package main
import (
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"net/http"
)
type myhandler struct {
}
func (h *myhandler) ServeHTTP(w http.ResponseWriter,
r *http.Request) {
fmt.Fprintf(w, "Hi from golang!\n")
}
func main() {
caCrt, err := ioutil.ReadFile("ca.crt")
if err != nil {
fmt.Println("ReadFile err:", err)
return
}
pool := x509.NewCertPool()
pool.AppendCertsFromPEM(caCrt)
s := &http.Server{
Addr: ":8081",
Handler: &myhandler{},
TLSConfig: &tls.Config{
ClientCAs: pool,
ClientAuth: tls.RequireAndVerifyClientCert,
},
}
fmt.Println("Listening https://127.0.0.1" + s.Addr)
err = s.ListenAndServeTLS("server.crt", "server.key")
if err != nil {
fmt.Println("ListenAndServeTLS err:", err)
}
}
|
最佳答案
查看完整内容
这就是个https的服务功能
https://bbs.125.la/forum.php?mod=viewthread&tid=14798213&highlight=HTTPS
这个地址的帖子就可以了
|