// AccessToken will get a new access token
AccessToken will get a new access token
// AccessToken will get a new access token
func (v *Redcat) AccessToken(username string, password string) (bool, error) {
	u, _ := url.ParseRequestURI(v.LoginURL)
	urlStr := fmt.Sprintf("%v", u)
	request := LoginRequest{
		Username: username,
		Password: password,
		AuthType: "U",
	}
	fmt.Println("Connecting to redcat", urlStr, request)
	body, err := json.Marshal(request)
	if err != nil {
		fmt.Println("Request marshal err", err)
		return false, err
	}
	client := &http.Client{}
	r, err := http.NewRequest("POST", urlStr, bytes.NewBuffer(body))
	if err != nil {
		fmt.Println("Redcat POST err ", err)
		return false, err
	}
	r.Header = http.Header(make(map[string][]string))
	r.Header.Set("Content-Type", "application/json")
	res, err := client.Do(r)
	if err != nil {
		fmt.Println("Redcat client.DO err ", err)
		return false, err
	}
	if res.StatusCode == 200 {
		rawResBody, err := ioutil.ReadAll(res.Body)
		if err != nil {
			fmt.Println("Redcat ReadAll err ", err)
			return false, err
		}
		var resp LoginResponse
		err = json.Unmarshal(rawResBody, &resp)
		if err != nil {
			fmt.Println("Redcat MARSHAL err ", err)
			return false, err
		}
		fmt.Println("Connection Response", resp, string(rawResBody))
		v.accessToken = resp.Token
		return resp.Success, nil
	}
	fmt.Println("Redcat Status Code ", res.StatusCode)
	return false, fmt.Errorf("Failed redcat login %s", res.Status)
}
func ( v * Redcat ) AccessToken ( username string , password string ) ( bool , error ) { u , _ := url . ParseRequestURI ( v . LoginURL ) urlStr := fmt . Sprintf ( " " , u ) request := LoginRequest { Username : username , Password : password , AuthType : " " , } fmt . Println ( " " , urlStr , request ) body , err := json . Marshal ( request ) if err != nil { fmt . Println ( " " , err ) return false , err } client := & http . Client { } r , err := http . NewRequest ( " " , urlStr , bytes . NewBuffer ( body ) ) if err != nil { fmt . Println ( " " , err ) return false , err } r . Header = http . Header ( make ( map [ string ] [ ] string ) ) r . Header . Set ( " " , " " ) res , err := client . Do ( r ) if err != nil { fmt . Println ( " " , err ) return false , err } if res . StatusCode == 200 { rawResBody , err := ioutil . ReadAll ( res . Body ) if err != nil { fmt . Println ( " " , err ) return false , err } var resp LoginResponse err = json . Unmarshal ( rawResBody , & resp ) if err != nil { fmt . Println ( " " , err ) return false , err } fmt . Println ( " " , resp , string ( rawResBody ) ) v . accessToken = resp . Token return resp . Success , nil } fmt . Println ( " " , res . StatusCode ) return false , fmt . Errorf ( " " , res . Status ) }
AccessToken will get a new access token
AccessToken will get a new access token