GO 语言来路伪装

package main

import (
   "log"
   "net/http"
   "net/http/httputil"
   "net/url"
)

type handle struct {
   host string
   port string
}

func (this *handle) ServeHTTP(w http.ResponseWriter, r *http.Request) {
   remote, err := url.Parse("http://" + this.host + ":" + this.port)
   if err != nil {
      panic(err)
   }
   proxy := httputil.NewSingleHostReverseProxy(remote)
   r.Header.Set("Referer","http://w.want.com/demo.html")
   proxy.ServeHTTP(w, r)
}

func startServer() {
   //被代理的服务器host和port
   h := &handle{host: "127.0.0.1", port: "8132"}
   err := http.ListenAndServe(":8133", h)
   if err != nil {
      log.Fatalln("ListenAndServe: ", err)
   }
}

func main() {
   startServer()
}

你可能感兴趣的:(GO 语言来路伪装)