private async Task RetrieveUid() { var client = new HttpClient(); var uri = new Uri("https://api.mojang.com/users/profiles/minecraft/" + Name); var response = await client.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead); while (response.StatusCode == (HttpStatusCode)429) { await Task.Delay(5000); response = await client.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead); } //Exception for user not found: Response 204 or 403, 404 etc. if (response.StatusCode != HttpStatusCode.OK) { Uid = CalculateOfflineUuid(Name); OfflineChar = true; return; } Stream respStream = await response.Content.ReadAsStreamAsync(); string nameUidString = await new StreamReader(respStream).ReadToEndAsync(); NameUid nameUid = JsonConvert.DeserializeObject <NameUid>(nameUidString); Uid = nameUid.id; }
private void RetrieveUid() { var client = new HttpClient(); var uri = new Uri("https://api.mojang.com/users/profiles/minecraft/" + Name); var response = client.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead).Result; while (response.StatusCode == (HttpStatusCode)429) { Thread.Sleep(5000); response = client.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead).Result; } //Exception for user not found: Response 204 if (response.StatusCode == HttpStatusCode.NoContent) { Uid = Name; offlineChar = true; return; } Stream respStream = response.Content.ReadAsStreamAsync().Result; string nameUidString = new StreamReader(respStream).ReadToEnd(); NameUid nameUid = JsonConvert.DeserializeObject <NameUid>(nameUidString); Uid = nameUid.id; }