type Values map[string][]string func ParseQuery(query string) (m Values, err error) { m = make(Values) err = parseQuery(m, query) return } func parseQuery(m Values, query string) (err error) { for query != "" { key := query if i := strings.IndexAny(key, "&;"); i >= 0 { key, query = key[:i], key[i+1:] } else { query = "" } if key == "" { continue } value := "" if i := strings.Index(key, "="); i >= 0 { key, value = key[:i], key[i+1:] } m[key] = append(m[key], value) } return err } func Test(w http.ResponseWriter, req *http.Request) { //fmt.Println(url.ParseQuery(req.URL.RawQuery)) //fmt.Println(req.RequestURI) v, _ := ParseQuery(req.URL.RawQuery) } func main() { http.HandleFunc("/test.php", Test) http.ListenAndServe(":8888", nil) select {} }
发表评论