Created
August 10, 2018 22:52
Request re-use
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"fmt" | |
"io/ioutil" | |
"net/http" | |
) | |
func main() { | |
client := &http.Client{} | |
buf := bytes.NewBufferString("hello, world") | |
req, err := http.NewRequest(http.MethodPost, "http://httpbin.org/anything", bytes.NewReader(buf.Bytes())) | |
if err != nil { | |
panic(err) | |
} | |
for i := 0; i < 10; i++ { | |
resp, err := client.Do(req) | |
if err != nil { | |
panic(err) | |
} | |
body, err := ioutil.ReadAll(resp.Body) | |
if err != nil { | |
panic(err) | |
} | |
defer resp.Body.Close() | |
fmt.Printf("resp status = %+v body = %+v\n", resp.StatusCode, string(body)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result: