Go相关
Go环境安装
Post请求
本文档使用MrDoc发布
返回首页
-
+
Post请求
2020年9月17日 15:36
admin
package main import ( "fmt" "io/ioutil" "net/http" "crypto/md5" "encoding/hex" "strings" "os" "time" ) func MD5(str string) string { h := md5.New() h.Write([]byte(str)) return hex.EncodeToString(h.Sum(nil)) } func main() { mobile := os.Args[1] username := "xwvoice2" password := "552512" secretkey := "0c+Vqc7NBWW3ZkV-" checktype := 1 timestamp := time.Now().UnixNano() / 1000000 sign := MD5(string(checktype) + string(mobile) + string(secretkey) + fmt.Sprintf("%d",timestamp)) url := "http://150.158.105.68:8080/hbck/check?mobile=" + mobile + "&username=" + username + "&password=" + password + "&sign=" + sign + "×tamp=" + fmt.Sprintf("%d",timestamp) + "&checktype=" + fmt.Sprintf("%d",checktype) fmt.Println(url) client := &http.Client{} req, err := http.NewRequest("POST", url , strings.NewReader("name=test")) if err != nil { // handle error } req.Header.Set("Content-Type","application/json; charset=utf-8") //req.Header.Set("Cookie", "name=anny") resp, err := client.Do(req) defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { // handle error } fmt.Println(string(body)) }
分享到: