Skip to content

Instantly share code, notes, and snippets.

@liangchaoboy
Last active February 22, 2018 13:22
Show Gist options
  • Save liangchaoboy/b286c4a72279d1b8a70554713435fa5a to your computer and use it in GitHub Desktop.
Save liangchaoboy/b286c4a72279d1b8a70554713435fa5a to your computer and use it in GitHub Desktop.
qiniuproxy
package main
import (
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"strings"
)
func main() {
fmt.Println("come on...")
http.HandleFunc("/path", ProxyServer)
err := http.ListenAndServe(":80", nil)
if err != nil {
log.Fatal("ListenAndServe:", err)
}
}
func ProxyServer(w http.ResponseWriter, req *http.Request) {
fmt.Println(req.Method)
rb, _ := ioutil.ReadAll(req.Body)
str := strings.Replace(string(rb), "ret=", "", 1)
fmt.Println(str)
httpDo(str)
io.WriteString(w, "hello world!")
}
func httpDo(str string) {
client := &http.Client{}
req, err := http.NewRequest("POST", "xx", strings.NewReader(str))
req.Header.Set("Content-Type", "text/plain")
resp, err := client.Do(req)
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
// handle error
}
fmt.Println(string(body))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment