summaryrefslogtreecommitdiff
path: root/post.go
diff options
context:
space:
mode:
Diffstat (limited to 'post.go')
-rw-r--r--post.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/post.go b/post.go
new file mode 100644
index 0000000..8252435
--- /dev/null
+++ b/post.go
@@ -0,0 +1,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()
+ }
+}