blob: 7f0622ddef00df2d59bde49976c991529f6fb3a1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
package main
import "fmt"
import "net/http"
import "os"
import "io/ioutil"
import "net/url"
import "strings"
func main() {
argc := len(os.Args)
if argc < 2 {
fmt.Println("usage: post url [key1=value1 [... keyn=valuen]]")
return
}
address := os.Args[1]
values := url.Values{}
for f := 2; f < argc; f++ {
val := strings.Split(os.Args[f], "=")
values.Add(val[0], val[1])
}
resp, err := http.PostForm(address, values)
if err != nil {
fmt.Println("Error getting",address,err)
} else {
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading",address,err)
} else {
fmt.Println(resp.Status, resp.Proto)
for k,v := range resp.Header {
fmt.Println(k,v)
}
fmt.Println(string(body))
}
resp.Body.Close()
}
}
|