func main() {
	c := http.Client{}
	url := "http://127.0.0.1:8080/newtask"
	data := map[string]string{
		"type": "MD5",
		"hash": "5ebe2294ecd0e0f08eab7690d2a6ee69",
	}

	req, err := c.PostForm(url, data)

	if err == nil {
		body, _ := ioutil.ReadAll(req.Body)
		fmt.Printf("%s\n", body)
		req.Body.Close()
	} else {
		fmt.Printf("Error: %v\n", err)
	}
	return
}
Exemple #2
0
func ObtainBearerToken(code string) {
	tokenUrl := "https://runkeeper.com/apps/token"
	formData := make(map[string][]string)
	formData["grant_type"] = []string{"authorization_code"}
	formData["code"] = []string{code}
	formData["client_id"] = []string{ClientId}
	formData["client_secret"] = []string{ClientSecret}
	formData["redirect_uri"] = []string{RedirectUri}
	client := new(http.Client)
	response, err := client.PostForm(tokenUrl, formData)
	responseJson := make(map[string]string)
	if err == nil {
		responseBody, _ := ioutil.ReadAll(response.Body)
		json.Unmarshal(responseBody, &responseJson)
		file, _ := os.Create(".bearer_token")
		file.WriteString(responseJson["access_token"])
		file.Close()
	} else {
		fmt.Print(err)
	}
}