Created
January 19, 2016 21:26
-
-
Save nesv/8ccbd9fdc414367d3531 to your computer and use it in GitHub Desktop.
Sample HTTP client
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 ( | |
"log" | |
"net/http" | |
"net/url" | |
"time" | |
) | |
func main() { | |
delay := time.Duration(1) * time.Second | |
resp, err := http.PostForm("http://your-server/work", url.Values{ | |
"delay": delay.String(), | |
"name": "Nick", | |
}) | |
if err != nil { | |
log.Fatalln(err) | |
} | |
defer resp.Close() | |
switch v := resp.StatusCode; v { | |
case http.StatusCreated: | |
log.Println("ok") | |
return | |
} | |
log.Fatalln("unexpected status from server:", resp.Status) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment