golang实现http post
发布时间:2020-12-16 18:24:08 所属栏目:大数据 来源:网络整理
导读:package mainimport ("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.NewRe
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("%+vn",req) //看下发送的结构 resp,err := client.Do(req) //发送 defer resp.Body.Close() //一定要关闭resp.Body data,_ := ioutil.ReadAll(resp.Body) fmt.Println(string(data),err) } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 如何使用Delphi中的DropBox REST API复制文件
- Learning Perl: 9.3. The join Function
- (高精度运算4.7.30)UVA 10579 Fibonacci Numbers(大数+斐波
- thinkphp3.2.3 分页代码分享
- 在Wireshark工具中加入lua脚本
- 【medium】17. Letter Combinations of a Phone Number 数字
- io – 在Lua中阅读整个文件
- Delphi Generics>具有默认值的字典
- 一个简单的Delphi与go lang通讯的例子
- NYOJ 517 最小公倍数 (1-n 个数的最小公倍数,大数)