标签:http io ar os sp for 数据 on ad
package main import ( "fmt" "io/ioutil" "net/http" "net/url" "strings" ) func main() { v := url.Values{} v.Set("huifu", "hello world") body := ioutil.NopCloser(strings.NewReader(v.Encode())) //把form数据编下码 client := &http.Client{} req, _ := http.NewRequest("POST", "http://192.168.2.83:8080/bingqinggongxiang/test2", body) req.Header.Set("Content-Type", "application/x-www-form-urlencoded; param=value") //这个一定要加,不加form的值post不过去,被坑了两小时 fmt.Printf("%+v\n", req) //看下发送的结构 resp, err := client.Do(req) //发送 defer resp.Body.Close() //一定要关闭resp.Body data, _ := ioutil.ReadAll(resp.Body) fmt.Println(string(data), err) }
标签:http io ar os sp for 数据 on ad
原文地址:http://my.oschina.net/tongjh/blog/348091