2020-04-02 11:42:31 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httputil"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
body := bytes.NewBufferString("All your base are belong to us")
|
2020-04-02 14:01:16 +00:00
|
|
|
req, err := http.NewRequest(http.MethodPost, "https://myapi.com/create", body)
|
2020-04-02 11:42:31 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
req.Header.Set("X-Source", "Zero Wing")
|
|
|
|
repr, err := httputil.DumpRequestOut(req, true)
|
|
|
|
if err == nil {
|
|
|
|
fmt.Println(string(repr))
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := http.DefaultClient.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2020-04-02 14:01:16 +00:00
|
|
|
defer resp.Body.Close()
|
2020-04-02 11:42:31 +00:00
|
|
|
fmt.Println(resp.StatusCode)
|
|
|
|
}
|