Skip to content

Instantly share code, notes, and snippets.

@corerman
Created January 24, 2018 12:57
Show Gist options
  • Save corerman/143c50bd478f37b9d4f35781271d46a9 to your computer and use it in GitHub Desktop.
Save corerman/143c50bd478f37b9d4f35781271d46a9 to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"net/url"
)
func main() {
request_url := "http://localhost/index.php"
// 要 POST的 参数
form := url.Values{
"username": {"xiaoming"},
"address": {"beijing"},
"subject": {"Hello"},
"from": {"china"},
}
// v := url.Values{}
// v.Set("type", "1")
// v.Set("device_id", deviceid)
// v.Set("open_id", openid)
// v.Set("device_num", dervicenum)
// v.Set("nickname", userInfo.Nickname)
// v.Set("sex", fmt.Sprintf("%d",userInfo.Sex))
// v.Set("city", userInfo.City)
// v.Set("province", userInfo.Province)
// v.Set("headimgurl", userInfo.Headimgurl)
// func Post(url string, bodyType string, body io.Reader) (resp *Response, err error) {
//对form进行编码
body := bytes.NewBufferString(form.Encode())
rsp, err := http.Post(request_url, "application/x-www-form-urlencoded", body)
if err != nil {
panic(err)
}
defer rsp.Body.Close()
body_byte, err := ioutil.ReadAll(rsp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(body_byte))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment