public async Task Test() { LogonInfo info = new LogonInfo { email = "*****@*****.**", password = "******", language = "da-DK" }; string token = await Login(info); client.DefaultRequestHeaders.Add("Session-Token", token); client.DefaultRequestHeaders.Add("Accept", "application/json, text/javascript, */*; q=0.01"); HttpResponseMessage geoStatus = await client.GetAsync("https://tracker-api-ws.husqvarna.net/services/robot/162205377-162600101/geoStatus/"); GeoStatus status = JsonConvert.DeserializeObject <GeoStatus>(await geoStatus.Content.ReadAsStringAsync()); await Task.Delay(5000); HttpResponseMessage geoStatus2 = await client.GetAsync("https://tracker-api-ws.husqvarna.net/services/robot/162205377-162600101/geoStatus/"); GeoStatus status2 = JsonConvert.DeserializeObject <GeoStatus>(await geoStatus2.Content.ReadAsStringAsync()); GpsInfoList infos = new GpsInfoList(status.geoInfos.gpsInfo); infos.Combine(status2.geoInfos.gpsInfo); }
private async Task <HttpResponseMessage> TryLogin(LogonInfo info) { string postBody = JsonConvert.SerializeObject(info); HttpResponseMessage response = await client.PostAsync("https://tracker-id-ws.husqvarna.net/imservice/rest/im/login", new StringContent(postBody, Encoding.UTF8, "application/json")); response.EnsureSuccessStatusCode(); return(response); }
private async Task <string> Login(LogonInfo info) { int maxTries = 5; int tries = 0; string token = null; while (true) { tries++; try { HttpResponseMessage response = await TryLogin(info); token = response.Headers.FirstOrDefault(x => x.Key.Contains("Session-Token")).Value?.FirstOrDefault(); } catch (Exception) { if (tries >= maxTries) { throw; } } if (!string.IsNullOrEmpty(token)) { return(token); } if (tries >= maxTries) { break; } } throw new LoginException("Unable to login - never recieved session token."); }