I just want to send a rest call with golang, but it failed, the error message : {"header":{"code":201,"desc":"param data not exist"}} . (but when I send rest request with postman ,it success) the code as follow
1 package main 2 3 import( 4 "net/http" 5 "fmt" 6 "strings" 7 "io/ioutil" 8 ) 9 func check(err error){ 10 if err !=nil{ 11 panic(err) 12 } 13 } 14 func main(){ 15 url:="http://ip:8080/api" 16 method:="POST" 17 da:="base64 encoded string" 18 data:=strings.NewReader(da) 19 req,err:=http.NewRequest(method,url,data) 20 check(err) 21 req.Header.Set("Content_Type","application/x-www-form-urlencoded") 22 client:=&http.Client{} 23 resp,err:=client.Do(req) 24 check(err) 25 defer resp.Body.Close() 26 result,err:=ioutil.ReadAll(resp.Body) 27 check(err) 28 fmt.Println(string(result[:])) 29 } -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.