TaskFlow/client/main.go

33 lines
756 B
Go
Raw Normal View History

2016-09-21 00:33:18 +08:00
package main
import "net/http"
2016-09-21 00:54:04 +08:00
import "net/url"
2016-09-21 00:33:18 +08:00
import "fmt"
import "io/ioutil"
func main() {
2016-09-21 00:54:04 +08:00
//client := &http.Client{}
//req, err := http.NewRequest("POST", "http://127.0.0.1:8081/api/get-token/", nil)
usernamePwd := url.Values{}
usernamePwd.Set("username", "suraj")
usernamePwd.Set("password", "suraj")
// if err != nil {
// fmt.Println("Unable to form a POST")
// }
//req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
//resp, err := client.Do(req)
resp, err := http.PostForm("http://127.0.0.1:8081/api/get-token/", usernamePwd)
2016-09-21 00:33:18 +08:00
if err != nil {
fmt.Println(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading body")
}
fmt.Println(string(body))
}