@kjk1/

gobook http client post url encoded

Go

No description

fork
loading
Files
  • main.go

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.2557695657043113","path":"main.go","file":{"path":"main.go","content":{"asEncoding":{"base64":"Ly8gbm8gcGxheWdyb3VuZApwYWNrYWdlIG1haW4KCmltcG9ydCAoCgkiZm10IgoJImlvL2lvdXRpbCIKCSJsb2ciCgkibmV0L2h0dHAiCgkibmV0L3VybCIKCSJ0aW1lIgopCgpmdW5jIG1haW4oKSB7CgkvLyA6c2hvdyBzdGFydAoJY2xpZW50IDo9ICZodHRwLkNsaWVudHt9CgljbGllbnQuVGltZW91dCA9IHRpbWUuU2Vjb25kICogMTUKCgl1cmkgOj0gImh0dHBzOi8vaHR0cGJpbi5vcmcvcG9zdCIKCWRhdGEgOj0gdXJsLlZhbHVlc3sKCQkibmFtZSI6ICBbXXN0cmluZ3siSm9obiJ9LAoJCSJlbWFpbCI6IFtdc3RyaW5neyJqb2huQGdtYWlsLmNvbSJ9LAoJfQoJcmVzcCwgZXJyIDo9IGNsaWVudC5Qb3N0Rm9ybSh1cmksIGRhdGEpCglpZiBlcnIgIT0gbmlsIHsKCQlsb2cuRmF0YWxmKCJjbGllbnQuUG9zRm9ybXQoKSBmYWlsZWQgd2l0aCAnJXMnXG4iLCBlcnIpCgl9CglkZWZlciByZXNwLkJvZHkuQ2xvc2UoKQoJXywgZXJyID0gaW91dGlsLlJlYWRBbGwocmVzcC5Cb2R5KQoJaWYgZXJyICE9IG5pbCB7CgkJbG9nLkZhdGFsZigiaW91dGlsLlJlYWRBbGwoKSBmYWlsZWQgd2l0aCAnJXMnXG4iLCBlcnIpCgl9CgoJZm10LlByaW50ZigiUG9zdEZvcm0oKSBzZW50ICclcycuIFJlc3BvbnNlIHN0YXR1cyBjb2RlOiAlZFxuIiwgZGF0YS5FbmNvZGUoKSwgcmVzcC5TdGF0dXNDb2RlKQoJLy8gOnNob3cgZW5kCn0="},"asBuffer":null},"loaded":true}}
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
// no playground
package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
	"net/url"
	"time"
)

func main() {
	// :show start
	client := &http.Client{}
	client.Timeout = time.Second * 15

	uri := "https://httpbin.org/post"
	data := url.Values{
		"name":  []string{"John"},
		"email": []string{"[email protected]"},
	}
	resp, err := client.PostForm(uri, data)
	if err != nil {
		log.Fatalf("client.PosFormt() failed with '%s'\n", err)
	}
	defer resp.Body.Close()
	_, err = ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Fatalf("ioutil.ReadAll() failed with '%s'\n", err)
	}

	fmt.Printf("PostForm() sent '%s'. Response status code: %d\n", data.Encode(), resp.StatusCode)
	// :show end
}