import ( fm "fmt" "net/url" rt "runtime" ) func main() { var urlStr string = "http://baidu.com/index.php/?abc=1_羽毛" l, err := url.ParseQuery(urlStr) fm.Println(l, err) l2, err2 := url.ParseRequestURI(urlStr) fm.Println(l2, err2) l3, err3 := url.Parse(urlStr) fm.Println(l3, err3) fm.Println(l3.Path) fm.Println(l3.RawQuery) fm.Println(l3.Query()) fm.Println(l3.Query().Encode()) fm.Println(l3.RequestURI()) fm.Printf("Hello World! version : %s", rt.Version()) }
输出:
map[http://baidu.com/index.php/?abc:[1_羽毛]] <nil>
http://baidu.com/index.php/?abc=1_羽毛 <nil>
http://baidu.com/index.php/?abc=1_羽毛 <nil>
/index.php/
abc=1_羽毛
map[abc:[1_羽毛]]
abc=1_%E7%BE%BD%E6%AF%9B
/index.php/?abc=1_羽毛
Hello World! version : go1.2成功: 进程退出代码 0.